← Back to learning path
Chapter · Published

Embeddings and vector indexes: reproducible retrieval from experiment to production

Choose an embedding model, distance metric, and batching strategy while keeping the index rebuildable.

Source: knowledge/p24-b/collection_6e8fbe1e8b1ea569a539e8a5/tutorials/rag-embedding-and-vector-indexing.mdRAG knowledge engineering
Chapter progress 0%Learning path progress 0% · 0/10 chapters completedContinue learning path →

A vector index is only a candidate retrieval layer. To make results reproducible, fix the embedding model, preprocessing rules, distance metric, and index parameters, and store them in index metadata.

Core concepts

Vectors from the same model can be compared directly. Store the model identifier, dimension, normalization method, and build time in the index. Changing any of these requires a new index version rather than mixing data in place.

import math

def cosine(a: list[float], b: list[float]) -> float:
    dot = sum(x * y for x, y in zip(a, b))
    na = math.sqrt(sum(x * x for x in a))
    nb = math.sqrt(sum(y * y for y in b))
    return dot / (na * nb) if na and nb else 0.0

assert round(cosine([1, 0], [1, 0]), 3) == 1.0

Steps

  1. Fix cleaning, chunking, and embedding model versions and write them into the index manifest.
  2. Use a small data set to verify dimensions, empty vectors, and duplicate-document handling.
  3. Choose distance and retrieval count, recording build parameters and failed batches.
  4. Compare recall and latency with an offline question set before introducing an approximate index.

When to use it

This workflow suits small and medium knowledge bases and production pipelines that need versioned rebuilds.

Common questions

Do I need a vector database? Not always. SQLite or an in-memory index can validate the workflow at small scale.

Can I reuse an old index after changing the embedding model? Usually not. Build a new version and evaluate it again.

Is a larger retrieval count always better? Too many candidates add noise and context cost. Let an evaluation set decide.

Official references

OpenAI Embeddings; Qdrant documentation.

Last checked: 2026-11-16. Use the linked documentation for current model and index behavior.

Related practical cases

KnowledgeCase study: blue-green RAG index release and rollbackKnowledgeCase study: a local SQLite policy-search RAGKnowledgeCase study: replaying RAG retrieval regression with a fixed question set

Related source resources

SourceQdrant

Further reading

KnowledgeRAG for Enterprise Knowledge: Architecture and PracticeKnowledgeDesigning Reliable AI Automation WorkflowsKnowledgeMultimodal AI Pipelines for Images, Text, and Audio
Product Hub Demo · V0.3