liveBook · Manning

Vector database

As explained in Building LLM Applications with DSPy

A vector store is a data system that indexes and retrieves numerical vector representations, typically by similarity.

A vector database stores embeddings so a query can retrieve the most similar items. In a RAG system, article titles and a user question are embedded; the closest titles identify articles whose contents can be added to the prompt. section 9.2

For a small corpus, DSPy can keep vectors in memory; for more than 20,000 documents, it selects Faiss. Other available choices include local databases and cloud services. section 9.2.1

Listing 9.3 Embedding text
import dspy
from sentence_transformers import SentenceTransformer

model = SentenceTransformer('BAAI/bge-small-en-v1.5')
embedder = dspy.Embedder(model.encode)  #1

question = "How can I add discounts to my service prices when customers pay for a plan?"

corpus = [  #2
    "Pricing Plans: Creating Discount Coupons", 
    "Pricing Plans: Using Discount Coupons", 
    "Wix Events: About the Event Details and Registration Form Pages", 
    "Wix Restaurants Request: Changing the Alignment of Your Menus",
    "Adding Pinterest Content to Your Site"
]

search = dspy.retrievers.Embeddings(embedder=embedder, corpus=corpus, k=2)  #3
prediction = search(question) #4
print(prediction)

See a DSPy example that embeds a question and article titles, then retrieves the two closest matches. section 9.2.1

How Building LLM Applications with DSPy covers it

How deep it goes
Explains embedding, storage, top-k retrieval, and a corpus-size-based backend choice without detailing database internals.
Examples
Uses a discount-pricing question to retrieve matching article titles, then applies the approach to a knowledge base.
What you can do after
Apply it via DSPy’s Embeddings retriever to return the top-k similar items from a corpus.
How it connects
Connects embeddings and retrievers to retrieval-augmented generation (RAG).

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 Building LLM Applications with DSPy. The section links point to the parts of the book it draws on.