Spring AI Vector Store: Setting Up Qdrant with Docker Compose
-
Last Updated:
-
By: javahandson
-
Series

Set up a Spring AI vector store with Qdrant and Docker Compose. Learn the Spring AI 2.0 dependencies, properties, data loading, and similarity search.
Most Spring AI demos keep everything in memory. That is fine when you are just testing a prompt. However, real apps need to search through documents, remember long chats, and find answers by meaning. For that, you need a Spring AI vector store. In this guide, we will set up Qdrant as our vector store and run it with Docker Compose.
In the earlier articles, we looked at chat models, chat memory, and embeddings. Now we join these ideas together. We will store embeddings in Qdrant. Then we will search them by meaning and feed the results to the LLM.
By the end of this guide, you will know:
Let us get started.
Let me start with the basic idea. A vector store is a database built to store and search vectors. A vector is just a long list of numbers. These numbers capture the meaning of some text, image, or audio.
An AI model called an embedding model creates these numbers. Text that means similar things gets similar vectors. So the words “car” and “automobile” land close together, even though the letters differ.
A normal database is great at exact matches. You ask for user id 42, and you get that exact row. But meaning does not work like that. A user may ask “how do I fix a cracked screen?” while your document says “repairing a broken display.”
A keyword search misses this. The words do not match, so the search returns nothing useful. A vector store, on the other hand, compares meaning. As a result, it finds the right document even when the words are different.
Here is the difference at a glance:
Spring AI gives you one common interface called VectorStore. Behind it, you can plug in many databases. For example, you can use Qdrant, Redis, PostgreSQL with pgvector, or others. Your code stays the same. Only the configuration changes.
This is the usual Spring style. You write against an abstraction. Then you swap the implementation without touching your business logic. So moving from one vector store to another is mostly a dependency and property change.
A vector store is the engine behind RAG, which stands for Retrieval Augmented Generation. The idea is simple. You give the LLM extra context from your own data before it answers. That way, the model does not have to guess.
The flow has three clear steps. First, you convert your documents into vectors and store them. Second, when a user asks a question, you turn the question into a vector too. Third, you search the store for the closest document vectors. Then you pass those documents to the LLM as context.
Without a vector store, you would stuff every document into the prompt. That wastes tokens and often confuses the model. With a vector store, you fetch only the few chunks that matter. So the prompt stays small, focused, and cheap.
| 💡 Interview Insight Interviewers often ask what a vector store adds over a normal database. Keep the answer short. A normal database matches exact keys, while a vector store matches meaning through vector similarity. That single difference is what makes semantic search and RAG possible. |

Spring AI supports many vector stores. So why do we pick Qdrant here? There are a few simple reasons.
First, Qdrant is open source and free to run locally. You do not need a cloud account or a credit card to start. Second, it is fast. Qdrant is written in Rust, and it talks over gRPC for low latency. Third, it runs as a small Docker container. Therefore, it fits perfectly with Spring Boot Docker Compose support.
A few more points make Qdrant friendly for learning:
To be fair, Qdrant is not the only good choice. If you already run PostgreSQL, pgvector may save you a database. If you already run Redis, that works too. Still, for a fresh project and a clean demo, Qdrant is hard to beat.
Here is how Qdrant stacks up against two other popular options. Treat this as a rough guide, not a hard rule:
Notice that each option shares the same Spring AI VectorStore interface. Therefore, your Java code barely changes between them. You mostly swap the starter dependency and a few properties. That portability is one of the best parts of Spring AI.
Before we write code, let us understand two small things about Qdrant. Both come up again later, so they are worth a minute now.
Qdrant exposes two ports, and they are not the same:
This trips up many beginners. They point Spring AI at 6333 and then wonder why nothing connects. So remember the rule. Spring AI uses 6334, while you use 6333 in the browser.
Qdrant groups vectors into collections. A collection is a bit like a table in a normal database. Each collection has a fixed vector size and a distance metric, such as cosine similarity.
In Spring AI, you give the collection a name through a property. If the collection does not exist yet, Spring AI can create it for you. However, you must opt in to that behavior, as we will see soon.
Now comes the fun part. We will run Qdrant with Docker Compose and let Spring Boot manage the container. This guide uses Spring AI 2.0, the current release line. Make sure Docker is installed and running first.
Create a file named compose.yaml in your project root. Then add the Qdrant service like this:
services:
qdrant:
image: 'qdrant/qdrant:latest'
ports:
- '6333:6333' # REST API and web dashboard
- '6334:6334' # gRPC API used by Spring AIA few notes on this file:
Next, add the required dependencies to your pom.xml. I am assuming the Spring AI BOM is already in place from the earlier articles. Here are the four pieces you need:
<!-- Lets Spring Boot start and stop the Qdrant container -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-docker-compose</artifactId>
<scope>runtime</scope>
</dependency>
<!-- Qdrant vector store starter (Spring Boot auto-configuration) -->
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-vector-store-qdrant</artifactId>
</dependency>
<!-- Core RAG module: RetrievalAugmentationAdvisor lives here -->
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-rag</artifactId>
</dependency>
<!-- QuestionAnswerAdvisor and VectorStoreChatMemoryAdvisor live here -->
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-vector-store-advisor</artifactId>
</dependency>The starter is the important one. With spring-ai-starter-vector-store-qdrant on the classpath, Spring Boot creates a VectorStore bean backed by Qdrant. You then inject that bean and use it.
One naming change deserves a flag here. In Spring AI 2.0, the advisor module was renamed. The old name was spring-ai-advisors-vector-store. The new name is spring-ai-vector-store-advisor. So if you copy an older tutorial, update this artifact id, or your build will fail.
| 💡 Interview Insight A common interview question asks which module holds which advisor. Keep it clear. The RetrievalAugmentationAdvisor sits in spring-ai-rag. The QuestionAnswerAdvisor and VectorStoreChatMemoryAdvisor sit in spring-ai-vector-store-advisor. Mixing these up is a frequent build error in real projects. |
Now tell Spring AI how to reach Qdrant. Add these lines to application.properties:
# Stop the Qdrant container when the app stops spring.docker.compose.stop.command=down # Qdrant connection settings spring.ai.vectorstore.qdrant.host=localhost spring.ai.vectorstore.qdrant.port=6334 spring.ai.vectorstore.qdrant.collection-name=javahandson # Let Spring AI create the collection if it is missing spring.ai.vectorstore.qdrant.initialize-schema=true
Let me explain the key properties:
This one is important, so I will slow down. In Spring AI 2.0, the property spring.ai.vectorstore.qdrant.initialize-schema defaults to false. That is a breaking change. In older versions, schema creation happened by default.
What does this mean for you? If you forget this property, Spring AI will not create the collection. Then your first add or search fails, because the collection is missing. So set initialize-schema to true for a fresh demo. For production, many teams create the collection in advance with the exact vector size they want.
After you start the app, you can confirm that Qdrant is running. Open your browser and go to the REST port:
http://localhost:6333/dashboard
The dashboard shows your collections and the points inside them. So once you load some data, refresh this page. You should see your collection with a growing point count. This is a quick way to check that storage really worked.
We have Qdrant running. Now let us put some data into it. In Spring AI, you add data as Document objects. The VectorStore then embeds each one and stores the vector.
Here is a small loader that pushes a few sentences into Qdrant at startup:
@Component
public class DataLoader {
private final VectorStore vectorStore;
public DataLoader(VectorStore vectorStore) {
this.vectorStore = vectorStore;
}
@PostConstruct
public void loadData() {
List<String> sentences = List.of(
"Java is used for building scalable enterprise applications.",
"Docker packages applications into lightweight containers.",
"Spring AI connects Spring Boot apps to AI models.",
"Qdrant is a fast vector database written in Rust."
);
List<Document> documents = sentences.stream()
.map(Document::new)
.toList();
vectorStore.add(documents);
}
}Notice how little code this takes. You wrap each sentence in a Document. Then you call vectorStore.add(). Spring AI does the rest for you.
Behind the scenes, two things happen on that one add() call:
Hard-coded sentences are fine for a demo. Real apps load data from files. For that, Spring AI offers document readers. One handy reader uses Apache Tika, which handles PDFs, Word files, and more.
Add the Tika reader dependency first:
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-tika-document-reader</artifactId>
</dependency>Then read the file, split it into chunks, and store the chunks:
@Component
public class PolicyLoader {
@Value("classpath:company-policy.pdf")
private Resource policyFile;
private final VectorStore vectorStore;
public PolicyLoader(VectorStore vectorStore) {
this.vectorStore = vectorStore;
}
@PostConstruct
public void loadPdf() {
TikaDocumentReader reader = new TikaDocumentReader(policyFile);
List<Document> docs = reader.get();
TextSplitter splitter = TokenTextSplitter.builder()
.withChunkSize(100)
.withMaxNumChunks(400)
.build();
vectorStore.add(splitter.split(docs));
}
}Why split the document into chunks? Because a whole PDF is too big to search well. Small chunks give sharper matches. Also, small chunks keep your prompts short, which saves tokens later.
Storing data is only half the story. The real power is search. Let us run a similarity search against Qdrant and see what comes back.
To search, you build a SearchRequest and call similaritySearch(). Here is the simplest form:
List<Document> results = vectorStore.similaritySearch(
SearchRequest.builder()
.query("Tell me about containers")
.topK(3)
.build());This asks Qdrant for the three closest documents to the query. Even though the query says “containers,” the Docker sentence should rank high. That is semantic search in action.
Sometimes you want only strong matches. A similarity threshold helps here. It drops results that are too weak:
SearchRequest searchRequest = SearchRequest.builder()
.query(message)
.topK(3)
.similarityThreshold(0.5)
.build();
List<Document> similarDocs = vectorStore.similaritySearch(searchRequest);The threshold runs from 0 to 1. A higher value means stricter matching. So 0.5 is a balanced start. Later, you can tune it based on your own data and results.
Now we close the loop. We take the search results, add them to the prompt, and ask the LLM. This is the heart of RAG. First, turn the documents into plain text:
String context = similarDocs.stream()
.map(Document::getText)
.collect(Collectors.joining(System.lineSeparator()));Then feed that context to the ChatClient along with the user question:
String answer = chatClient.prompt()
.system(spec -> spec.text(promptTemplate)
.param("documents", context))
.user(message)
.call()
.content();The model now answers using your documents, not just its training data. As a result, the reply is grounded in your own content. That is exactly what we wanted.
| 💡 Interview Insight An interviewer may ask how topK and the similarity threshold differ. Explain it simply. The topK value sets how many results you want back. The similarity threshold sets how close those results must be. You often use both together to keep the context small and relevant. |
The manual approach above is good for learning. You can see every step. However, it has repeated code. Spring AI offers a cleaner way with a built-in advisor.
This advisor handles retrieval for you. It searches the vector store, builds the context, and adds it to the prompt. You just wire it once. Define the advisor bean like this:
@Bean
public RetrievalAugmentationAdvisor retrievalAugmentationAdvisor(
VectorStore vectorStore) {
return RetrievalAugmentationAdvisor.builder()
.documentRetriever(
VectorStoreDocumentRetriever.builder()
.vectorStore(vectorStore)
.topK(3)
.similarityThreshold(0.5)
.build())
.build();
}Remember, this advisor lives in the spring-ai-rag module. So keep that dependency in your pom.xml.
Next, add the advisor to your ChatClient. Then the retrieval happens on every call, with no manual search:
@Bean
public ChatClient chatClient(ChatClient.Builder builder,
RetrievalAugmentationAdvisor advisor) {
return builder
.defaultAdvisors(advisor)
.build();
}Now your controller is clean. You send the user message, and the advisor fetches the right context behind the scenes:
@GetMapping("/document/chat")
public String documentChat(@RequestParam String message) {
return chatClient.prompt()
.user(message)
.call()
.content();
}See the difference? No SearchRequest. No manual joining of text. The advisor did all of that for us. For most apps, this is the way to go.
Let me share a few lessons that will save you debugging time. I have hit most of these myself.
| 💡 Interview Insight A frequent interview follow-up is why a Spring AI 2.0 app connects to Qdrant but finds no data. The usual cause is a missing collection. Since initialize-schema now defaults to false, the schema is never created unless you opt in. Mention this gotcha, and you show real hands-on experience. |
A: A vector store is a database that stores text as vectors and searches it by meaning. Spring AI exposes one common VectorStore interface, so you can plug in Qdrant, pgvector, Redis, and others without changing your Java code.
A: Spring AI connects over the gRPC port 6334. Port 6333 is the REST API and web dashboard, which you open in the browser. Pointing Spring AI at 6333 is a common reason the connection fails.
A: In Spring AI 2.0, spring.ai.vectorstore.qdrant.initialize-schema defaults to false. This is a breaking change from older versions. Set it to true so Spring AI creates the collection, or create the collection in advance for production.
A: Use org.springframework.ai:spring-ai-starter-vector-store-qdrant. The older name spring-ai-qdrant-store-spring-boot-starter belongs to Spring AI 1.x, so update it if you copy an older tutorial.
A: Wrap your text in Document objects and call vectorStore.add(documents). Spring AI embeds each document and stores it in the Qdrant collection. For PDFs, use TikaDocumentReader and split the text into small chunks first.
A: The topK value sets how many results you get back. The similarity threshold sets how close those results must be, on a scale of 0 to 1. You often use both together to keep the retrieved context small and relevant.
Setting up a Spring AI vector store with Qdrant is simpler than it first looks. Docker Compose runs the database for you. The starter wires everything up. Then a few properties connect the two.
Here is a quick recap of the steps:
Start small with a handful of sentences and one search. Once that works, load a real PDF and switch to the advisor. This way, you build a solid RAG foundation without getting lost in the details.