Semantic Search
How Wolbarg embeds queries and retrieves memories by cosine similarity.
What is it?
Semantic search is the default recall() path: embed the query, compare against stored memory embeddings, return the top-K closest records.
Why does it exist?
Agents ask questions in natural language. Exact string match fails when vocabulary drifts; vectors catch meaning.
How does it work?
embedding.embed(query)produces a query vector- Storage runs nearest-neighbor search (sqlite-vec / pgvector or in-process cosine)
- Optional filters (
agent, metadata, archived) shrink the candidate set - Results are ranked by similarity and trimmed to
topK
const results = await ctx.recall({
query: "How do recurring invoices work?",
topK: 5,
threshold: 0.3,
filter: { agent: "research" },
});When should it be used?
Always. Semantic search is the baseline. Add Hybrid Search when exact tokens matter, Rerankers when precision matters, and Metadata Filtering to scope corpora.
Performance notes
- Latency is dominated by embedding network calls + vector scan size
- Keep
thresholdabove 0 for noisy corpora - Prefer metadata filters before raising
topK