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

























