liveBook · Manning

Similarity search

As explained in Domain-Specific Small Language Models

The process of searching external sources to find information relevant to a query or prompt.

Knowledge retrieval searches private or public sources for information relevant to a prompt, then supplies that context to an LLM. In retrieval-augmented generation (RAG), retrieval precedes natural-language generation and can support source checking for transparency and accuracy. section 2.2

Operationally, retrieval involves:

  • Searching a corpus using embeddings and vector similarity. section 13.3
  • Storing embeddings and metadata in a vector database, with approximate-nearest-neighbor indexes improving search speed. section 13.3
  • Comparing RAG with prompt engineering or fine-tuning according to freshness, domain specificity, cost, and task requirements. section 2.2 section 2.6

Searching a local LanceDB table

Encode the query "blocked KV-cache," search the embedding column, and return the top three results. The returned passage discusses blocked KV-cache and continuous batching, with a similarity score of 0.7036938667297363. section 13.3

How Domain-Specific Small Language Models covers it

How deep it goes
Explains the retrieval-generation pipeline and demonstrates embedding storage, schema definition, indexing, and querying, without detailing ranking theory.
Examples
Uses LanceDB tables, cosine-similarity ANN indexes, and a blocked KV-cache query returning ranked passages.
What you can do after
Build retrieval-backed applications with LanceDB, embeddings, vector indexes, and an LLM generation step.
How it connects
Connects embeddings, vector databases, RAG, LLMs, prompt engineering, fine-tuning, and source traceability.

Also explained in

Compare how 22 books explain similarity search →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Domain-Specific Small Language Models. The section links point to the parts of the book it draws on.