vector-search-patterns

Implementation guidance for finding similar text by comparing numerical representations called embeddings. It uses cosine similarity, which measures how closely two directions match, directly in TypeScript.

In plain words
What is it for?
Use it when implementing in-process vector search, similarity tests, and hybrid search in the Akashic Context memory system.
Why use it?
It avoids relying on a separate SQLite extension and provides a way to combine meaning-based matches with keyword matches.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/tostechbr/memoryclaw/vector-search-patterns
Any agent
npx skills add tostechbr/memoryClaw --skill vector-search-patterns
Clone the repo
git clone --depth 1 https://github.com/tostechbr/memoryClaw

Made for: Claude Code, Codex.

Per session 42 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,181 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00042 $0.01181
Opus 5 $0.00021 $0.00590
Sonnet 5 $0.00008 $0.00236
Haiku 4.5 $0.00004 $0.00118

Measured 2d ago against content hash 7a0032a24b6e, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

vector-search-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude/skills/vector-search-patterns/SKILL.md · 146 lines

How it starts

The opening of the file, as written. The whole thing — 146 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Vector Search Patterns — Akashic Context Sprint 1

Design Decision (D1)

No sqlite-vec extension. Cosine similarity implemented in TypeScript directly.

Why: Embeddings already stored as JSON in chunks.embedding column. sqlite-vec has platform loading issues. In-process is sufficient for ~2000 chunks/user.

cosine Similarity Function

Add as module-level function in storage.ts (NOT exported — internal utility):

function cosineSimilarity(a: number[], b: number[]): number {
  let dot = 0, magA = 0, magB = 0;
  for (let i = 0; i < a.length; i++) {
    dot += a[i] * b[i];
    magA += a[i] * a[i];
    magB += b[i] * b[i];
  }
  const mag = Math.sqrt(magA) * Math.sqrt(magB);
  if (mag === 0) return 0;
  return dot / mag;
}

Mathematical properties (use in tests):

  • cosineSimilarity([1,0], [1,0])1.0 (identical)
  • cosineSimilarity([1,0], [0,1])0.0 (orthogonal)
  • cosineSimilarity([1,0], [-1,0])-1.0 (opposite)

searchVectorInProcess() in storage.ts

Add alongside existing searchVector() method:

searchVectorInProcess(params: SearchVectorParams): VectorSearchResult[] {
  let sql = `
    SELECT id, path, source, start_line as startLine, end_line as endLine, text, embedding
    FROM chunks
  `;
  const queryParams: unknown[] = [];

  if (params.source) {
    sql += " WHERE source = ?";
    queryParams.push(params.source);
  }

  const rows = this.db.prepare(sql).all(...queryParams) as Array<{
    id: string; path: string; source: string;
    startLine: number; endLine: number; text: string; embedding: string;
  }>;

  const queryEmb = params.embedding;

  return rows
    .map(row => {
      let chunkEmb: number[];
      try {
        chunkEmb = JSON.parse(row.embedding) as number[];
      } catch {
        return null;
      }
      const similarity = cosineSimilarity(queryEmb, chunkEmb);
      return {
        id: row.id,
        path: row.path,
        source: row.source,
        startLine: row.startLine,
        endLine: row.endLine,
        text: row.text,
        distance: 1 - similarity, // Lower is better (consistent with searchVector interface)
      };
    })
    .filter((r): r is VectorSearchResult => r !== null && r.distance <= (1 - 0.3))
    .sort((a, b) => a.distance - b.distance)
    .slice(0, params.limit);
}

Read the full file on GitHub · 146 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 146 lines · 42 tokens per session scan A 7a0032a24b6e

Subscribe to this mod's changes

vector-search-patterns is a skill published in the GitHub repository tostechbr/memoryClaw (8 stars, last pushed 5mo ago), licensed MIT. It adds 42 tokens to every session and 1,181 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

stale-sweep

Sweep the googleapis/mcp-toolbox repo for issues and PRs with no real activity in N days (default 60), sort each by whose silence it is (the author's, ours, or nobody's), and draft the nudge or close comment. Use whenever a maintainer asks for a stale sweep, backlog cleanup, or an SLO check, e.g. "stale sweep", "find…

googleapis/mcp-toolbox · 159 tokens

triage-issues

Triage GitHub issues in the googleapis/mcp-toolbox repo: propose the correct labels (type / priority / product / status), check for duplicates, verify a bug has enough info to act on, and draft a triage comment. Use whenever a maintainer asks you to triage, label, categorize, prioritize, or "look at" an issue (or a…

googleapis/mcp-toolbox · 164 tokens

github-issue-triage

Issue triage and lifecycle management agent for ZeroClaw. Use this skill whenever the user wants to: triage open issues, close stale/duplicate/fixed issues, apply labels, run a backlog sweep, enforce the current issue stale policy, or handle a specific issue. Trigger on: 'triage issues', 'issue triage', 'sweep…

zeroclaw-labs/zeroclaw · 140 tokens

trello

Manages Trello boards, lists, and cards via the Trello REST API. Use when the user wants to create cards, move tasks between lists, list boards, add comments, archive cards, or check what is on a Trello board. Handles authentication, pagination, and rate-limit awareness for all Trello REST endpoints.

elizaOS/eliza · 69 tokens

copilotkit-contribute

Use when contributing to the CopilotKit open-source project — forking, cloning, setting up the monorepo, creating branches, running tests, and submitting pull requests against CopilotKit/CopilotKit.

CopilotKit/CopilotKit · 49 tokens

triage

Triage open herdr GitHub issues into a concise decision-first Markdown table. Use when the user says "triage", asks to triage open issues, asks which issues need attention, or wants issue priority/recommendation lights for herdr.

herdrdev/herdr · 53 tokens