How Memex finds the right note
Memex answers a search in two ways at once: by the exact words of the query (lexical search, ranked with BM25) and by its meaning (semantic search, with multilingual embeddings). The two result lists are merged with Reciprocal Rank Fusion. Everything is computed on the Memex server, and only notes the caller is allowed to read take part.
The short version
When you or your assistant search a brain, Memex looks for notes in two complementary ways.
- By words. It finds the notes that contain the words you typed. This is what you want for a name, a reference number or an exact phrase.
- By meaning. It finds the passages that talk about the same thing, even with other words or in another language. The query "comment poser des vacances" finds a note titled "Requesting holidays".
- Together. The two lists are merged into one. A note found both ways rises to the top.
Notes are indexed in the background, a few seconds after each change, so an assistant always searches the current state of the brain. Nothing is sent to an outside service to do this: the index and the model live inside the Memex server.
Lexical search: an inverted index ranked with BM25
Each brain has its own full-text index, built with Tantivy, a search engine library written in Rust. An inverted index maps every term to the notes that contain it, and BM25 ranks the matches: a term that is rare in the brain and frequent in a note counts for more than a common one.
- Text is lower-cased and accents are folded, so
resumematchesrésumé. - Every word of the query must match, in the title, the tags, the path or the body of a note; a match in the title weighs more. Quoted text is searched as a phrase, and the word being typed matches as a prefix.
- The index is updated incrementally: a write, a move or a deletion changes only the entries of that note. It is derived data and can be rebuilt from the files at any time.
- A result carries the path, the title and an excerpt with the matched words.
Lexical search is always available. It is the right tool for exact queries: proper nouns, client names, ticket numbers, function names, error messages.
Semantic search: multilingual embeddings
An embedding is a list of numbers, a vector, that represents the meaning of a piece of text: two passages about the same subject get vectors that point in nearly the same direction. Memex encodes each passage of a note as a 256-dimension vector and compares it with the vector of the query by cosine similarity.
The model is potion-multilingual-128M, a static embedding model (Model2Vec) covering 101 languages, published under the MIT licence. "Static" means there is no neural network to run at query time: each token of the vocabulary has a vector, and the vector of a text is the normalised average of the vectors of its tokens. That is what lets the model run in plain Rust inside the Memex binary, on any CPU, without a GPU and without a separate inference service.
- Because the model is multilingual, retrieval is cross-lingual: a question in French finds a note written in English.
- The search is an exact scan of the vectors of the brain, not an approximate index. A note scores as its best passage.
- Passages under a minimum similarity are treated as unrelated and left out.
A static model does not read word order. It is good at topics and paraphrases, and weaker at negation and at questions whose answer shares no vocabulary field with the note. This is one reason the default mode is hybrid rather than semantic alone.
On a self-hosted instance, semantic search is off until an administrator enables it, because the model is a separate download of about 480 MB. Until then, search runs by keywords and the same requests keep working.
Rank fusion: Reciprocal Rank Fusion
BM25 scores and cosine similarities live on unrelated scales, so they cannot be added or compared directly. Ranks can. Reciprocal Rank Fusion (RRF) gives each note a score of 1 / (60 + rank) in each list and sums the two. A note that both methods place near the top ends above a note that only one of them found.
RRF needs no calibration, no training data and no tuning for a particular brain, which matters for a tool that is installed on corpora nobody has seen in advance. Each hybrid result says which side found it: keyword, semantic or both. A keyword hit shows its excerpt with the matches highlighted; a semantic-only hit shows its best passage.
Structural chunking: passages of about 250 tokens
A whole note is too coarse a unit for semantic search: a long document covers several subjects, and its average meaning matches none of them well. Memex therefore cuts each Markdown or text note into passages of about 250 tokens, following the structure of the document instead of a fixed character count.
- A passage never crosses a heading.
- Cuts fall at sentence boundaries.
- A code block is kept whole when it is small enough.
- Consecutive passages of a section overlap slightly, so a sentence at a boundary keeps its context.
- YAML front matter is not embedded.
- The title of the note, the headings above the passage and the tags of the note are put in front of each passage before it is encoded, so a passage is understood in its context.
The link graph
Notes link to each other with wiki links, written [[Note name]]. Memex extracts them and maintains a directed graph: for any note, its outgoing links, its backlinks (the notes that point to it) and its unresolved links (references to notes that do not exist yet).
People see this as a graph view and a backlinks list in the app. Assistants get it through the get_links tool: after finding one relevant note by search, an assistant can follow its links to gather the surrounding context, the way a person would click through a wiki.
Incremental indexing
Indexing happens in the background and never delays a write. A worker embeds a note a few seconds after its last change. There is no queue that could be lost: the work to do is the difference between the file index and the table of embeddings, recomputed at each pass, so a restart resumes exactly where things were.
- A moved or copied note reuses the vectors of the identical content instead of being encoded again.
- A deleted note loses its vectors.
- Only
.md,.markdownand.txtfiles are embedded, and only their first megabyte. - For a few seconds after an edit, a note can still be found through its previous content.
Everything is computed on the server, within your rights
The full-text index, the tokenizer, the embedding model and the vector comparison all run inside the Memex process. No note, query or vector is sent to a third-party service, and there is no remote inference. The only network access semantic search ever makes is the one-time download of the model, whose files are verified against SHA-256 hashes compiled into the binary.
Search goes through the same authorisation layer as every other operation. Passages of notes the caller cannot read are skipped before any score is computed: they are not ranked and then removed. A hidden note therefore neither appears in the results nor changes the order or the scores of the visible ones. This holds for a person, for a guest, and for an AI client limited to a few folders.
The design choices, limits and measurements are documented in the product repository: semantic search and design decisions. To see how an assistant uses these tools, read For your AI.