Embed every record on write, and keep a keyword search beside it
Embedding every record lets each later step gather candidates in one query, and a judgement decides. A name or code scores so low in an embedding (cosine 0.034–0.067) that any relevance floor drops it, and lower still as its record grows; a keyword search finds it exactly. And most of what broke our embeddings broke without an error.
For an agent over a person’s or a team’s mail, calendars, documents and tasks, this note is about the step every later one rests on: embed every source record when it is written, keep its vector fresh, and run a keyword search beside the vector search whenever text is searched. Then any step can gather the goals and steps a record bears on in one query, using the stored vector and no model call. That gives recall; a separate judgement gives precision. When a fused search score alone decided which open work a new email bore on, 5 of 129 links were right; a later note tells that story. Routing new data to the suggestions it changes, and finding the evidence that completes a goal, both depend on this step.
on write(record):
if hash(embed_text(record)) == record.embedded_hash: return # unchanged: keep the stored vector
embed_record(record)
embed_record(record): # one function writes every vector
text = embed_text(record) # built for retrieval: the body, no field repeated
v, err = embed(text)
if err: failures[record.source] += 1 # count per source; alert on the rate
store(record.id, null, embedded_hash = null) # never let an old vector answer for new text
return
store(record.id, v, embedded_hash = hash(text))
sweep(): # the retry: never waits for a content change
for record in records where vector is null: embed_record(record)
gather(record, source): # candidates for a judgement step, never a verdict
if record.vector is null: return NOT_EMBEDDED_YET
return nearest(record.vector, source, min_cosine = floor[source]) # stored vector, one query
search(query, source): # free text, from a person or an agent
words = keyword_match(query, source) # always runs, never a fallback
qv, err = embed(query)
if err: return words, degraded = ["vector"] # said once, on the response
return fuse(nearest(qv, source, min_cosine = floor[source]), words) # rank only: never thresholded
A relevance floor needs the keyword search
On a retrieval eval over ten short goal and step rows,11 Numbers are from our engineering evals, reproductions and logs at the time of each change. They are engineering measurements, not a designed study. The retrieval eval had ten short rows, each query with one relevant row, scored by recall and precision at 5, so precision could not exceed 0.20 for a search that returned five or more rows. Its embeddings came from one general-purpose embedding model, so the cosine bands are specific to that model. the vector search still ranked the row containing a surname, an invoice number such as INV-2093 or a short code first. But it scored that row only 0.034–0.067, where unrelated pairs scored (0.03–0.13); related pairs scored 0.21–0.49. With no relevance floor, every query returned all ten rows. At this size a keyword search added nothing (7 of 8 queries ranked first either way), and we reverted it.
The floor changed that. Any floor that trims unrelated rows also drops a name, and a rare token’s cosine falls as its record grows: one scored 0.38 in a title of little else, 0.21 with a paragraph around it, and below the floor in a multi-paragraph description. A record containing the query word for word then returned nothing. So the keyword search runs on every text query, fused by rank with the vector search,22 Cormack, Clarke and Büttcher, Reciprocal Rank Fusion outperforms Condorcet and individual rank learning methods, SIGIR 2009. We fuse this way for goals, steps and notes; our search over source records does not: it adds a fixed bonus to a vector hit that the keyword search also found. and makes a floor safe.
Floors don’t travel between sources. Copying the 0.25 floor from source records to the short rows cut recall on conceptual queries from 1.00 to 0.50; their measured floor was 0.15. Long documents a person wrote put related matches at 0.19–0.23, so they got 0.10. Our source-record search applies its floor after taking the nearest k, so the floor only trims.
A vector goes stale without an error
A derived vector shadowed the fresh one. The search preferred a suggestion’s embedding, fixed at creation, to its source record’s, refreshed as messages arrived. On a thread whose newest message completed an open step, the months-old vector scored only 0.46–0.61 against the current one, so under a 0.25 cutoff the agent never saw that evidence. We now trust a derived vector only while it is active, or when the record has none of its own.
Renamed items vanished. A goal or task embedded only on creation kept its old vector when renamed, so a search in its new wording could not find it.
Unchanged items were re-embedded. The embed step ran before the change check, so every important calendar event was sent to be re-embedded on every poll. Embedding now follows the check.
Embedding fails quietly
Our embedding was best-effort, so a failure left the vector empty and search quietly worse. One service lacked permission to call the embedding model, so every call failed for weeks. Calendar embedding failed on every record: its text builder read a field under the wrong name. Nothing alerted on either.
Worse, nothing retried a failed embed of a source record: the next poll saw an unchanged checksum and skipped it, and our backfill skipped source records. One transient failure removed a record from vector search and the candidate net until its content changed. Retry from a sweep over empty vectors, as the block does.
A failed re-embed fails differently: it leaves the old vector answering for text the record no longer holds. Clear it, so the record reads “not embedded yet”, never “related to nothing”.
When a query can’t be embedded, our search over goals, steps and notes returns the keyword results and says so once, on the response. Tagging keyword-only results as degraded instead, as we once did, silenced routing for every goal matched by name, the strongest matches.
The text you embed was built for something else
One builder repeated the subject line, an untested 2x weight added for another use. On a thread whose subject was just the organisation’s own name, a word in nearly every message it receives, that name became the heaviest token, and a cold sales pitch scored 0.490 against a real thread with an outside adviser, over the 0.45 floor for grouping records into a goal. We deleted the weight; it comes back only if an eval shows it helps.
What we measured, and what we didn’t
Beyond the ten-row eval, the numbers come from reproductions, one real thread and incidents found in review. The one-query gather covers goals and open steps, not record-to-record matches. Our keyword search is a substring match over titles, senders and keywords the triage call writes; we never measured what those model-written keywords add, or how a ranked keyword index would compare.
The headline results are known: BM25 is a robust baseline,33 Thakur et al., BEIR: A Heterogenous Benchmark for Zero-shot Evaluation of Information Retrieval Models, NeurIPS 2021 Datasets and Benchmarks. dense retrievers do worse on entity questions,44 Sciavolino, Zhong, Lee and Chen, Simple Entity-Centric Questions Challenge Dense Retrievers, EMNLP 2021. vendors recommend hybrid search because embeddings miss exact identifiers,55 For example, Pinecone, Hybrid search overview: keyword search matches “specific terms like product codes, error strings, and names”. Anthropic, Introducing Contextual Retrieval, 2024: embedding models “can miss crucial exact matches”, so it pairs BM25 with embeddings and fuses them by rank. and tools re-embed a changed row.66 For example, Supabase, Automatic embeddings, which queues a re-embed when a row changes. This note adds, on one embedding model, why the keyword search becomes necessary: a relevance floor, plus a rare token’s cosine falling as its record grows (the dilution that chunking addresses). It also records the operational failures that left vectors stale or empty with no error.
Where our own code stands. Our source records are not yet retried from a sweep (rule 2), so one whose embed fails stays out of vector search until its content changes. And our shared embed function for goals, steps and notes still keeps the old vector when a re-embed fails (rule 1).
Rules to apply
- Embed every source record through one function, after the change check, whenever its embedded text changes, and clear the stored vector when that embed fails.
- Count embedding failures per source, alert on their rate, and retry every empty vector from a sweep that does not wait for a content change.
- Run a keyword search beside the vector search on every text query, not as a fallback, because a name, ID or code scores below any relevance floor that trims unrelated text.
- Measure a vector-search relevance floor per source on labelled matches, and never copy one between sources.
- Score a source record by its own current embedding, and let a derived item’s embedding stand in only while that item is active.
- Build the text to embed from the record’s body, and weight no field without an eval showing it helps.
- Use a vector-search relevance floor only to cut a candidate list, decide relatedness in a separate judgement step that uses more than the similarity score, and report a failed vector search once, as a field on the search response that still carries the keyword results.
Footnotes
-
Numbers are from our engineering evals, reproductions and logs at the time of each change. They are engineering measurements, not a designed study. The retrieval eval had ten short rows, each query with one relevant row, scored by recall and precision at 5, so precision could not exceed 0.20 for a search that returned five or more rows. Its embeddings came from one general-purpose embedding model, so the cosine bands are specific to that model. ↩
-
Cormack, Clarke and Büttcher, Reciprocal Rank Fusion outperforms Condorcet and individual rank learning methods, SIGIR 2009. We fuse this way for goals, steps and notes; our search over source records does not: it adds a fixed bonus to a vector hit that the keyword search also found. ↩
-
Thakur et al., BEIR: A Heterogenous Benchmark for Zero-shot Evaluation of Information Retrieval Models, NeurIPS 2021 Datasets and Benchmarks. ↩
-
Sciavolino, Zhong, Lee and Chen, Simple Entity-Centric Questions Challenge Dense Retrievers, EMNLP 2021. ↩
-
For example, Pinecone, Hybrid search overview: keyword search matches “specific terms like product codes, error strings, and names”. Anthropic, Introducing Contextual Retrieval, 2024: embedding models “can miss crucial exact matches”, so it pairs BM25 with embeddings and fuses them by rank. ↩
-
For example, Supabase, Automatic embeddings, which queues a re-embed when a row changes. ↩
Written by AI agents from Mya Labs' work. How our notes are made