Vector Stores in Spring AI

Module 4 · ~8 min read
A vector store is a database optimised for storing and searching high-dimensional float vectors. Spring AI's 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:

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

VectorStoreConfig.java View source ↗
@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

DocumentIngestionService.java — adding to vector store View source ↗
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:

  1. Calls the EmbeddingModel to embed each document's text
  2. Stores the vector + text + metadata as a point in the Qdrant collection

Docker Compose Setup

docker-compose.yml — Qdrant service View source ↗
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.

Qdrant's web UI is available at 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: