You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Introduces a builder pattern for configuring QdrantVectorStore instances to
provide a more flexible and type-safe way to create and configure vector stores.
This change:
- Makes configuration more intuitive through fluent builder methods
- Improves validation by enforcing required parameters at compile time
- Deprecates old constructors in favor of the builder pattern
- Adds comprehensive builder tests to ensure reliability
- Updates reference documentation with builder usage examples
- Maintains backward compatibility while providing a clear migration path
The builder pattern simplifies QdrantVectorStore configuration by providing
clear method names, proper validation, and better IDE support through method
chaining. This makes the API more user-friendly and helps prevent configuration
errors at compile time rather than runtime.
This section walks you through setting up the Qdrant `VectorStore` to store document embeddings and perform similarity searches.
4
4
5
-
link:https://www.qdrant.tech/[Qdrant] is an open-source, high-performance vector search engine/database.
5
+
link:https://www.qdrant.tech/[Qdrant] is an open-source, high-performance vector search engine/database. It uses HNSW (Hierarchical Navigable Small World) algorithm for efficient k-NN search operations and provides advanced filtering capabilities for metadata-based queries.
6
6
7
7
== Prerequisites
8
8
9
9
* Qdrant Instance: Set up a Qdrant instance by following the link:https://qdrant.tech/documentation/guides/installation/[installation instructions] in the Qdrant documentation.
10
10
* If required, an API key for the xref:api/embeddings.adoc#available-implementations[EmbeddingModel] to generate the embeddings stored by the `QdrantVectorStore`.
11
11
12
-
To set up `QdrantVectorStore`, you'll need the following information from your Qdrant instance: `Host`, `GRPC Port`, `Collection Name`, and `API Key` (if required).
13
-
14
12
NOTE: It is recommended that the Qdrant collection is link:https://qdrant.tech/documentation/concepts/collections/#create-a-collection[created] in advance with the appropriate dimensions and configurations.
15
13
If the collection is not created, the `QdrantVectorStore` will attempt to create one using the `Cosine` similarity and the dimension of the configured `EmbeddingModel`.
16
14
17
15
== Auto-configuration
18
16
19
-
Then add the Qdrant boot starter dependency to your project:
17
+
Spring AI provides Spring Boot auto-configuration for the Qdrant Vector Store.
18
+
To enable it, add the following dependency to your project's Maven `pom.xml` file:
The vector store implementation can initialize the requisite schema for you, but you must opt-in by specifying the `initializeSchema` boolean in the appropriate constructor or by setting `...initialize-schema=true` in the `application.properties` file.
39
-
40
-
NOTE: this is a breaking change! In earlier versions of Spring AI, this schema initialization happened by default.
41
-
42
-
43
-
The Vector Store, also requires an `EmbeddingModel` instance to calculate embeddings for the documents.
44
-
You can pick one of the available xref:api/embeddings.adoc#available-implementations[EmbeddingModel Implementations].
45
-
46
-
For example to use the xref:api/embeddings/openai-embeddings.adoc[OpenAI EmbeddingModel] add the following dependency to your project:
TIP: Refer to the xref:getting-started.adoc#dependency-management[Dependency Management] section to add the Spring AI BOM to your build file.
66
-
Refer to the xref:getting-started.adoc#repositories[Repositories] section to add Milestone and/or Snapshot Repositories to your build file.
67
38
68
-
To connect to Qdrant and use the `QdrantVectorStore`, you need to provide access details for your instance.
69
-
A simple configuration can either be provided via Spring Boot's _application.properties_,
39
+
Please have a look at the list of xref:#qdrant-vectorstore-properties[configuration parameters] for the vector store to learn about the default values and configuration options.
70
40
71
-
[source,properties]
72
-
----
73
-
spring.ai.vectorstore.qdrant.host=<host of your qdrant instance>
74
-
spring.ai.vectorstore.qdrant.port=<the GRPC port of your qdrant instance>
75
-
spring.ai.vectorstore.qdrant.api-key=<your api key>
76
-
spring.ai.vectorstore.qdrant.collection-name=<The name of the collection to use in Qdrant>
41
+
TIP: Refer to the xref:getting-started.adoc#repositories[Repositories] section to add Milestone and/or Snapshot Repositories to your build file.
77
42
78
-
# API key if needed, e.g. OpenAI
79
-
spring.ai.openai.api.key=<api-key>
80
-
----
43
+
The vector store implementation can initialize the requisite schema for you, but you must opt-in by specifying the `initializeSchema` boolean in the builder or by setting `...initialize-schema=true` in the `application.properties` file.
44
+
45
+
NOTE: this is a breaking change! In earlier versions of Spring AI, this schema initialization happened by default.
81
46
82
-
TIP: Check the list of xref:#qdrant-vectorstore-properties[configuration parameters] to learn about the default values and configuration options.
47
+
Additionally, you will need a configured `EmbeddingModel` bean. Refer to the xref:api/embeddings.adoc#available-implementations[EmbeddingModel] section for more information.
83
48
84
-
Now you can Auto-wire the Qdrant Vector Store in your application and use it
49
+
Now you can auto-wire the `QdrantVectorStore` as a vector store in your application.
85
50
86
51
[source,java]
87
52
----
88
53
@Autowired VectorStore vectorStore;
89
54
90
55
// ...
91
56
92
-
List<Document> documents = List.of(
57
+
List<Document> documents = List.of(
93
58
new Document("Spring AI rocks!! Spring AI rocks!! Spring AI rocks!! Spring AI rocks!! Spring AI rocks!!", Map.of("meta1", "meta1")),
94
59
new Document("The World is Big and Salvation Lurks Around the Corner"),
95
60
new Document("You walk forward facing the past and you turn back toward the future.", Map.of("meta2", "meta2")));
@@ -98,62 +63,48 @@ List <Document> documents = List.of(
You can use the following properties in your Spring Boot configuration to customize the Qdrant vector store.
70
+
=== Configuration Properties
108
71
109
-
[cols="3,5,1",stripes=even]
110
-
|===
111
-
|Property| Description | Default value
112
-
113
-
|`spring.ai.vectorstore.qdrant.host`| The host of the Qdrant server. | localhost
114
-
|`spring.ai.vectorstore.qdrant.port`| The gRPC port of the Qdrant server. | 6334
115
-
|`spring.ai.vectorstore.qdrant.api-key`| The API key to use for authentication with the Qdrant server. | -
116
-
|`spring.ai.vectorstore.qdrant.collection-name`| The name of the collection to use in Qdrant. | -
117
-
|`spring.ai.vectorstore.qdrant.use-tls`| Whether to use TLS(HTTPS). | false
118
-
|`spring.ai.vectorstore.qdrant.initialize-schema`| Whether to initialize the backend schema or not | false
119
-
|===
120
-
121
-
== Metadata filtering
122
-
123
-
You can leverage the generic, portable link:https://docs.spring.io/spring-ai/reference/api/vectordbs.html#_metadata_filters[metadata filters] with the Qdrant vector store.
124
-
125
-
For example, you can use either the text expression language:
72
+
To connect to Qdrant and use the `QdrantVectorStore`, you need to provide access details for your instance.
73
+
A simple configuration can be provided via Spring Boot's `application.yml`:
126
74
127
-
[source,java]
75
+
[source,yaml]
128
76
----
129
-
vectorStore.similaritySearch(
130
-
SearchRequest.defaults()
131
-
.withQuery("The World")
132
-
.withTopK(TOP_K)
133
-
.withSimilarityThreshold(SIMILARITY_THRESHOLD)
134
-
.withFilterExpression("author in ['john', 'jill'] && article_type == 'blog'"));
77
+
spring:
78
+
ai:
79
+
vectorstore:
80
+
qdrant:
81
+
host: <qdrant host>
82
+
port: <qdrant grpc port>
83
+
api-key: <qdrant api key>
84
+
collection-name: <collection name>
85
+
use-tls: false
86
+
initialize-schema: true
87
+
batching-strategy: TOKEN_COUNT # Optional: Controls how documents are batched for embedding
135
88
----
136
89
137
-
or programmatically using the `Filter.Expression` DSL:
90
+
Properties starting with `spring.ai.vectorstore.qdrant.*` are used to configure the `QdrantVectorStore`:
138
91
139
-
[source,java]
140
-
----
141
-
FilterExpressionBuilder b = new FilterExpressionBuilder();
NOTE: These filter expressions are converted into the equivalent Qdrant link:https://qdrant.tech/documentation/concepts/filtering/[filters].
92
+
[cols="2,5,1",stripes=even]
93
+
|===
94
+
|Property | Description | Default Value
95
+
96
+
|`spring.ai.vectorstore.qdrant.host`| The host of the Qdrant server | `localhost`
97
+
|`spring.ai.vectorstore.qdrant.port`| The gRPC port of the Qdrant server | `6334`
98
+
|`spring.ai.vectorstore.qdrant.api-key`| The API key to use for authentication | -
99
+
|`spring.ai.vectorstore.qdrant.collection-name`| The name of the collection to use | `vector_store`
100
+
|`spring.ai.vectorstore.qdrant.use-tls`| Whether to use TLS(HTTPS) | `false`
101
+
|`spring.ai.vectorstore.qdrant.initialize-schema`| Whether to initialize the schema | `false`
102
+
|`spring.ai.vectorstore.qdrant.batching-strategy`| Strategy for batching documents when calculating embeddings. Options are `TOKEN_COUNT` or `FIXED_SIZE` | `TOKEN_COUNT`
103
+
|===
153
104
154
105
== Manual Configuration
155
106
156
-
Instead of using the Spring Boot auto-configuration, you can manually configure the `QdrantVectorStore`. For this you need to add the `spring-ai-qdrant-store` dependency to your project:
107
+
Instead of using the Spring Boot auto-configuration, you can manually configure the Qdrant vector store. For this you need to add the `spring-ai-qdrant-store` to your project:
157
108
158
109
[source,xml]
159
110
----
@@ -168,35 +119,79 @@ or to your Gradle `build.gradle` build file.
NOTE: These (portable) filter expressions get automatically converted into the proprietary Qdrant link:https://qdrant.tech/documentation/concepts/filtering/[filter expressions].
Copy file name to clipboardExpand all lines: spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vectorstore/qdrant/QdrantVectorStoreAutoConfiguration.java
+8-3Lines changed: 8 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -77,9 +77,14 @@ public QdrantVectorStore vectorStore(EmbeddingModel embeddingModel, QdrantVector
0 commit comments