Vector Stores in Spring AI
VectorStore interface abstracts over Qdrant, pgvector, Pinecone, Weaviate, and others — your application code uses the same API regardless of which backend is running.
The VectorStore Interface
Two methods cover 95% of RAG use cases:
add(List<Document> documents)— embeds each document and stores it with its metadatasimilaritySearch(SearchRequest request)— embeds the query and returns the top-K most similar documents
Qdrant: The Power RAG Choice
Qdrant is an open-source, Rust-based vector database with a gRPC API. Spring AI communicates with it via gRPC (port 6334) for low latency. Qdrant stores vectors in collections — Power RAG uses a single collection named power_rag_docs.
VectorStoreConfig
@Bean
public QdrantVectorStore vectorStore(QdrantClient qdrantClient,
EmbeddingModel embeddingModel) {
return QdrantVectorStore.builder(qdrantClient, embeddingModel)
.collectionName(collectionName)
.initializeSchema(true)
.build();
}
initializeSchema(true) tells Spring AI to create the Qdrant collection on startup if it does not already exist. This makes deployment zero-config — just start the service and the collection is ready.
Adding Documents
List<Document> docs = chunks.stream()
.map(c -> new Document(c.getText(), c.getMetadata()))
.toList();
vectorStore.add(docs);
When vectorStore.add(docs) is called, Spring AI automatically:
- Calls the
EmbeddingModelto embed each document's text - Stores the vector + text + metadata as a point in the Qdrant collection
Docker Compose Setup
qdrant:
image: qdrant/qdrant:latest
ports:
- "6333:6333" # HTTP REST (for Qdrant Web UI / manual queries)
- "6334:6334" # gRPC (used by Spring AI)
volumes:
- qdrant_data:/qdrant/storage
The named volume qdrant_data persists vectors across container restarts. Without it, all indexed documents would be lost every time the container is recreated.
http://localhost:6333/dashboard when running locally. You can browse collections, inspect points, and run ad-hoc searches — useful for debugging indexing issues.Metadata in Spring AI Documents
The second argument to new Document(text, metadata) is a Map<String, Object>. Metadata is stored alongside the vector in Qdrant as a payload. Common metadata fields in Power RAG:
file_name— original filenamedocument_id— UUID linking back to the PostgreSQL documents tablepage_number— for PDFsrow_number— for Excelsection_title— heading text when availablechunk_index— position within the document