Embeddings and chunking
CoreTurn documents into searchable meaning with a chunking strategy that holds context.
Concepts
Semantic chunkingSplit on meaning and structure, not blind fixed character counts.
Semantic chunking splits a document at natural boundary points, such as paragraph breaks, section headings, or sentence clusters with low cross-sentence similarity, rather than at a fixed character or token count. Fixed-size splitting is fast to implement but routinely severs a sentence from the context it depends on, so the retrieved chunk is technically on-topic but missing the surrounding reasoning. Splitting on meaning keeps each chunk self-contained enough that a language model can use it without needing what was cut away.
In practice, a good chunking strategy is often the highest-leverage tuning knob in a RAG pipeline. Measure recall@k before and after changing your chunking logic; the improvement is usually larger than switching embedding models.
Sources
Full definition in the glossaryContextual retrievalPrepend surrounding context to each chunk so fragments stay grounded.
Contextual retrieval prepends a short, chunk-specific summary to each chunk before embedding it, so the vector carries the fragment's meaning in context rather than in isolation. A chunk that reads 'The result was 42%' becomes searchable as 'In the Q3 2024 earnings section, the gross margin was 42%.' Anthropic's research shows this technique reduces retrieval failures by up to 49% on its own, and by up to 67% when combined with reranking.
The technique is especially valuable for long documents where late sections depend heavily on earlier setup. The context prepended at indexing time is cheap to generate in bulk with a fast model, and it does not change the retrieval API at all.
Sources
Matryoshka embeddingsTruncate vector dimensions to trade a little recall for speed.
Matryoshka Representation Learning (MRL) trains a single embedding model so that the first N dimensions of its output already form a meaningful, lower-dimensional representation of the full vector. This means you can truncate the vector to 256 or 512 dimensions at query time and still get most of the recall, at a fraction of the storage cost and query latency compared to using the full 1536 or 3072-dimensional output.
OpenAI's text-embedding-3 models support MRL natively via the `dimensions` parameter. The practical pattern is to store and search at a reduced dimension, then optionally use the full vector only for reranking the shortlisted candidates.
Sources
Technologies
Voyage / OpenAI embeddingsHosted models that turn text into search vectors.
Hosted embedding APIs turn text into dense vectors without requiring you to run or manage an embedding model. OpenAI's text-embedding-3 family and Voyage AI's domain-optimized models are the most widely deployed options. The critical production constraint is that all documents must be embedded with the same model version; switching models requires a full re-index, so the choice of provider is a migration decision, not just a quality one.
Voyage AI offers domain-specific models tuned for code, finance, and law that consistently outrank general-purpose models on those corpora. OpenAI's models support Matryoshka dimension truncation, which is useful for cost and latency budgets.
Sources
Full definition in the glossaryIn production
The discipline that separates a shipped system from a demo.
Evaluate retrieval aloneMeasure recall@k before blaming the model; bad answers usually start as bad retrieval.
Retrieval and generation are separate failure modes and must be evaluated separately. When a RAG system gives a bad answer, the cause is almost always a retrieval problem: the right document was never in the top-k results the model saw. Measuring recall@k, precision@k, and mean reciprocal rank (MRR) on the retriever in isolation tells you exactly how good your index is before a language model ever gets involved.
Running a retrieval-only eval is also much cheaper than running a full end-to-end eval, so it can run on every index change. A common mistake is to skip this step and spend engineering effort prompt-tuning around a fundamentally broken retriever.
Sources
Re-embed on model changeSwitching embedding models means rebuilding the index; plan the migration up front.
Every embedding model produces vectors in its own high-dimensional space, and distances between those vectors are only meaningful within that space. Switching embedding models, even to a newer version of the same provider's model, makes every stored vector incomparable to the new query vectors. The result is either silent degradation or total retrieval failure.
Treating the index as rebuildable from the start is what makes a model migration tractable: keep your raw documents in a document store, run a backfill job that re-embeds everything with the new model in a shadow index, validate recall@k on the shadow index, and cut over atomically. Never plan to migrate an embedding model without a full re-index budget.
Sources