Class QdrantVectorStore
java.lang.Object
org.springframework.ai.vectorstore.observation.AbstractObservationVectorStore
org.springframework.ai.vectorstore.qdrant.QdrantVectorStore
- All Implemented Interfaces:
Consumer<List<Document>>
,DocumentWriter
,VectorStore
,org.springframework.beans.factory.InitializingBean
public class QdrantVectorStore
extends AbstractObservationVectorStore
implements org.springframework.beans.factory.InitializingBean
Qdrant vectorStore implementation. This store supports creating, updating, deleting,
and similarity searching of documents in a Qdrant collection.
The store uses Qdrant's vector search functionality to persist and query vector embeddings along with their associated document content and metadata. The implementation leverages Qdrant's HNSW (Hierarchical Navigable Small World) algorithm for efficient k-NN search operations.
Features:
- Automatic schema initialization with configurable collection creation
- Support for cosine similarity distance metric
- Metadata filtering using Qdrant's filter expressions
- Configurable similarity thresholds for search results
- Batch processing support with configurable strategies
- Observation and metrics support through Micrometer
Basic usage example:
QdrantVectorStore vectorStore = QdrantVectorStore.builder(qdrantClient)
.embeddingModel(embeddingModel)
.initializeSchema(true)
.build();
// Add documents
vectorStore.add(List.of(
new Document("content1", Map.of("key1", "value1")),
new Document("content2", Map.of("key2", "value2"))
));
// Search with filters
List<Document> results = vectorStore.similaritySearch(
SearchRequest.query("search text")
.withTopK(5)
.withSimilarityThreshold(0.7)
.withFilterExpression("key1 == 'value1'")
);
Advanced configuration example:
QdrantVectorStore vectorStore = QdrantVectorStore.builder(qdrantClient, embeddingModel)
.collectionName("custom-collection")
.initializeSchema(true)
.batchingStrategy(new TokenCountBatchingStrategy())
.observationRegistry(observationRegistry)
.customObservationConvention(customConvention)
.build();
Requirements:
- Running Qdrant instance accessible via gRPC
- Collection with vector size matching the embedding model dimensions
- Since:
- 1.0.0
- Author:
- Anush Shetty, Christian Tzolov, EddĂș MelĂ©ndez, Josh Long, Soby Chacko, Thomas Vitale
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Builder for creating instances ofQdrantVectorStore
. -
Field Summary
FieldsFields inherited from class org.springframework.ai.vectorstore.observation.AbstractObservationVectorStore
batchingStrategy, embeddingModel
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Protected constructor for creating a QdrantVectorStore instance using the builder pattern. -
Method Summary
Modifier and TypeMethodDescriptionvoid
static QdrantVectorStore.Builder
builder
(io.qdrant.client.QdrantClient qdrantClient, EmbeddingModel embeddingModel) Creates a new QdrantBuilder instance.createObservationContextBuilder
(String operationName) Create a newVectorStoreObservationContext.Builder
instance.void
Adds a list of documents to the vector store.void
Deletes a list of documents by their IDs.protected void
doDelete
(Filter.Expression filterExpression) Template method for concrete implementations to provide filter-based deletion logic.doSimilaritySearch
(SearchRequest request) Performs a similarity search on the vector store.<T> Optional<T>
Returns the native client if available in this vector store implementation.Methods inherited from class org.springframework.ai.vectorstore.observation.AbstractObservationVectorStore
add, delete, delete, similaritySearch
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.ai.document.DocumentWriter
write
Methods inherited from interface org.springframework.ai.vectorstore.VectorStore
accept, delete, getName, similaritySearch
-
Field Details
-
DEFAULT_COLLECTION_NAME
- See Also:
-
-
Constructor Details
-
QdrantVectorStore
Protected constructor for creating a QdrantVectorStore instance using the builder pattern.- Parameters:
builder
- theQdrantVectorStore.Builder
containing all configuration settings- Throws:
IllegalArgumentException
- if qdrant client is missing- Since:
- 1.0.0
- See Also:
-
-
Method Details
-
builder
public static QdrantVectorStore.Builder builder(io.qdrant.client.QdrantClient qdrantClient, EmbeddingModel embeddingModel) Creates a new QdrantBuilder instance. This is the recommended way to instantiate a QdrantVectorStore.- Parameters:
qdrantClient
- the client for interfacing with Qdrant- Returns:
- a new QdrantBuilder instance
-
doAdd
Adds a list of documents to the vector store.- Specified by:
doAdd
in classAbstractObservationVectorStore
- Parameters:
documents
- The list of documents to be added.
-
doDelete
Deletes a list of documents by their IDs.- Specified by:
doDelete
in classAbstractObservationVectorStore
- Parameters:
documentIds
- The list of document IDs to be deleted.
-
doDelete
Description copied from class:AbstractObservationVectorStore
Template method for concrete implementations to provide filter-based deletion logic.- Overrides:
doDelete
in classAbstractObservationVectorStore
- Parameters:
filterExpression
- Filter expression to identify documents to delete
-
doSimilaritySearch
Performs a similarity search on the vector store.- Specified by:
doSimilaritySearch
in classAbstractObservationVectorStore
- Parameters:
request
- TheSearchRequest
object containing the query and other search parameters.- Returns:
- A list of documents that are similar to the query.
-
afterPropertiesSet
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
Exception
-
createObservationContextBuilder
Description copied from class:AbstractObservationVectorStore
Create a newVectorStoreObservationContext.Builder
instance.- Specified by:
createObservationContextBuilder
in classAbstractObservationVectorStore
- Parameters:
operationName
- the operation name- Returns:
- the observation context builder
-
getNativeClient
Description copied from interface:VectorStore
Returns the native client if available in this vector store implementation. Note on usage: 1. Returns empty Optional when no native client is available 2. Due to Java type erasure, runtime type checking is not possible Example usage: When working with implementation with known native client: Optionalclient = vectorStore.getNativeClient(); Note: Using Optional<?> will return the native client if one exists, rather than an empty Optional. For type safety, prefer using the specific client type. - Specified by:
getNativeClient
in interfaceVectorStore
- Type Parameters:
T
- The type of the native client- Returns:
- Optional containing native client if available, empty Optional otherwise
-