liveBook · Manning

Vector database

As explained in LLMs in Production

A vector database is a database optimized for storing and retrieving numerical vector representations using similarity-based search.

Suppose you want to find an image like one you have, but you do not know its ID or the right keywords. A vector database lets you search for nearby representations instead. It stores vectors, such as embeddings, alongside metadata; its distinguishing strength is similarity search, not storage alone. Searches can use Euclidean distance, cosine similarity, or dot product similarity. section 3.4.5

Choose how to use one based on the retrieval job:

  • Use vector search when a similar item is easier to specify than an exact ID or keyword. Traditional database indexes and text search remain useful when you know what to look for. section 3.4.5
  • Consider a feature store alongside the vector database, not necessarily instead of it: a feature store can be an abstraction built on top. Multiple data sources, embedding models, and frequent updates make management harder. section 3.4.5
  • For a small dataset, consider in-memory similarity search with Faiss or USearch. Milvus offers a locally run, Docker-based database, managed clusters, and a GPU-enabled option. section 10.2.1

Retrieving Python coding examples

A coding copilot can use retrieval-augmented generation (RAG) to add relevant coding context without fine-tuning its model. One implementation loads 18.6K Python instruction-and-code examples into Milvus, chunks and embeds them in batches, and stores IDs, embeddings, and JSON metadata in a collection. An IVF_FLAT index groups embeddings into clusters to accelerate similarity search. A query about classifying MNIST is embedded and searched for nearby instructions; the returned examples include handwritten-digit classification tasks. Using an organization’s changing codebase instead would require a pipeline to ingest and update that code. section 10.2 section 10.2.2

    collection.load()      #1

    query = (             #2
        "Construct a neural network model in Python to classify "
        "the MNIST data set correctly."
    )
    search_embedding = python_code_ingestion.embedder.encode(query)
    search_params = {
        "metric_type": "L2",
        "params": {"nprobe": 10},     #3
    }
    results = collection.search(
        [search_embedding],
        "embeddings",
        search_params,
        limit=3,
        output_fields=["metadata"],
    )
    for hits in results:
        for hit in hits:
            print(hit.distance)
            print(hit.entity.metadata["instruction"])

The Milvus search listing shows the query-to-embedding step, L2 search parameters, a three-result limit, and retrieval of instruction metadata. section 10.2.2

How LLMs in Production covers it

How deep it goes
Defines vector search and works through Milvus ingestion, indexing, and querying, without constructing a database engine.
Examples
Uses reverse image search and a Milvus collection of Python coding tasks queried with an MNIST classification request.
What it assumes
Assumes Python and Docker for the hands-on setup while introducing vector database basics through a local deployment.
What you can do after
Apply it via Milvus to ingest embedded coding examples and retrieve similar instructions for a RAG application.
How it connects
Connects embeddings, similarity search, feature stores, retrieval-augmented generation, and IVF_FLAT indexing.

Also explained in

Compare how 26 books explain vector database →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of LLMs in Production. The section links point to the parts of the book it draws on.