Embedding and Feature Pipelines: Keeping Vectors Fresh
You'll learn to
- -Describe a pipeline that keeps an index in step with its source documents
- -Use content fingerprints to embed only what changed, and remove what was deleted
- -Explain why vectors from two different encoders cannot be mixed
- -Plan an encoder upgrade as a full rebuild into a new index followed by a switch
Tip: the highlighter is on - just select any text below to mark it. Use the highlighter button up top to change color or turn it off. Highlights are saved on this device only. Log in to save them to your account instead.
A search index is a copy of your documents in a form that is fast to search. Like any copy, it goes stale. Documents are edited, added and deleted every day, and an index that does not follow them gives out-of-date answers, or worse, cites a policy that was withdrawn last week. Embedding and feature pipelines are the jobs that keep the copy in step.
An Analogy: A Library Card Catalog
A library keeps a card catalog for its books. When a book is revised, the librarian rewrites only that card. When a book is withdrawn, its card is pulled. If the library switches to an entirely different cataloging system, every card must be rewritten in the new system, and the new catalog is built on the side and swapped in once it is ready, so patrons are never left with half of each.
The Pipeline
- -Detect changes: compare each document's fingerprint, or listen to change events from the source, as in the event-driven chapter.
- -Prepare: clean, chunk and attach metadata such as source, owner, permissions and date.
- -Embed: compute vectors only for new or changed chunks, in batches.
- -Upsert: write vectors by a stable id, so running the job twice changes nothing. The job must be idempotent.
- -Delete: remove the vectors of anything deleted upstream. This is also how deletion requests are honored.
- -Record: store the encoder version and a timestamp with each vector, so you can see how fresh it is.
The code is a toy index of 1,000 documents. It fingerprints each document and embeds only what changed. A nightly sync then sees 37 edited documents, 5 deleted ones and 12 new ones. Finally it tries to search the index with a query from a different encoder version, and rebuilds under the new one.
The first build embedded all 1,000 documents. The nightly sync embedded 49, the 37 edited and 12 new, and removed 5, touching 54 of 1,007 documents. Running the same sync again embedded 0, which is what idempotent means. If each document is about 500 tokens, a full rebuild would embed 503,500 tokens and the sync 24,500, about twenty times fewer. That is the saving from detecting changes.
The error message shows the rule that shapes upgrades. Vectors from different encoders live in different spaces, so a query vector from one encoder compared with document vectors from another produces numbers that look valid and mean nothing. The index must record which encoder built it, and the query side must use the same one. To upgrade the encoder you embed every document again, 1,007 embeddings here, into a second index, test it against your evaluation set, and only then switch an alias to it, as in the registry chapter. The old index stays until the new one is proven.
Watch for deletions and permissions. A document removed upstream but still in the index will keep appearing in answers. Store access rules as metadata and filter on them at query time. The same idea applies to the features of classic ML systems, where the feature store chapter covers keeping values consistent between training and serving.
Interview Signal is part of Pro
See a real weak answer next to a real strong one for this exact topic.
Quiz is part of Pro
Test what you just read with a short quiz, and bank the XP.
Discussion0
Join the Discussion
Sign in to leave comments, reply to others, or like insights.
No comments yet. Be the first to start the thread!