Principle:0xK3vin MegaMemory Semantic Search
| Knowledge Sources | |
|---|---|
| Domains | NLP, Embeddings, Information_Retrieval |
| Last Updated | 2026-10-27 12:00 GMT |
Overview
A retrieval technique that embeds a natural-language query and a corpus into the same vector space, then ranks corpus items by cosine similarity to the query.
Description
Semantic search (also called dense retrieval) replaces lexical matching (BM25, TF-IDF) with a learned embedding model that maps text to dense vectors. The query and each candidate are embedded by the same model; similarity is computed as the cosine of the angle between vectors. Because the model captures meaning rather than surface tokens, it retrieves relevant concepts even when the query uses different vocabulary than the stored text.
Problem solved: In a knowledge graph where concepts are described in natural language (e.g., "Two-pass graph merge with conflict tracking"), an agent asking "how does merging handle edges?" would fail a keyword search because the words differ. Semantic search bridges this vocabulary gap by operating in a shared meaning space.
Context: In MegaMemory, every concept node stores a 384-dimensional embedding of its "kind: name — summary" text. The understand tool embeds the agent's query and brute-force ranks all active nodes by cosine similarity, returning the top K with full context (children, edges, parent). This is the primary retrieval mechanism for pre-task context loading.
Usage
Use this principle when:
- You store human-readable descriptions and need to retrieve them by meaning, not exact keywords
- The query vocabulary may differ from the stored descriptions (paraphrase retrieval)
- The corpus is small-to-medium (brute-force search is acceptable without an ANN index)
- You need offline/local search with no API keys or network dependency
Theoretical Basis
Given an embedding function , semantic search computes:
and returns the top-K candidates by descending similarity.
Pseudo-code:
# Abstract algorithm (NOT real implementation)
query_vec = embed(query) # 384-dim, L2-normalized
scores = []
for candidate in corpus:
cand_vec = candidate.embedding # precomputed, stored
scores.append((candidate, cosine(query_vec, cand_vec)))
scores.sort(key=lambda x: -x[1]) # descending
return scores[:top_k]
When the embedding model L2-normalizes outputs (as all-MiniLM-L6-v2 does with normalize: true), the cosine similarity reduces to the dot product, and all vectors lie on the unit hypersphere.
Related Pages
Implemented By
- Implementation:0xK3vin_MegaMemory_MCP_Tools_Core
- Implementation:0xK3vin_MegaMemory_Embeddings_Module
- Implementation:0xK3vin_MegaMemory_Web_Graph_Explorer_Server