Class QdrantVectorStore

java.lang.Object
org.springframework.ai.vectorstore.observation.AbstractObservationVectorStore
org.springframework.ai.vectorstore.qdrant.QdrantVectorStore
All Implemented Interfaces:
Consumer<List<org.springframework.ai.document.Document>>, org.springframework.ai.document.DocumentWriter, org.springframework.ai.vectorstore.VectorStore, org.springframework.beans.factory.InitializingBean

public class QdrantVectorStore extends org.springframework.ai.vectorstore.observation.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 Classes
    Modifier and Type
    Class
    Description
    static class 
    Builder for creating instances of QdrantVectorStore.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     

    Fields inherited from class org.springframework.ai.vectorstore.observation.AbstractObservationVectorStore

    batchingStrategy, embeddingModel
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Protected constructor for creating a QdrantVectorStore instance using the builder pattern.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    builder(io.qdrant.client.QdrantClient qdrantClient, org.springframework.ai.embedding.EmbeddingModel embeddingModel)
    Creates a new QdrantBuilder instance.
    org.springframework.ai.vectorstore.observation.VectorStoreObservationContext.Builder
     
    void
    doAdd(List<org.springframework.ai.document.Document> documents)
    Adds a list of documents to the vector store.
    void
    doDelete(List<String> documentIds)
    Deletes a list of documents by their IDs.
    protected void
    doDelete(org.springframework.ai.vectorstore.filter.Filter.Expression filterExpression)
     
    List<org.springframework.ai.document.Document>
    doSimilaritySearch(org.springframework.ai.vectorstore.SearchRequest request)
    Performs a similarity search on the vector store.
    <T> Optional<T>
     

    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 java.util.function.Consumer

    andThen

    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

  • Constructor Details

  • Method Details

    • builder

      public static QdrantVectorStore.Builder builder(io.qdrant.client.QdrantClient qdrantClient, org.springframework.ai.embedding.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

      public void doAdd(List<org.springframework.ai.document.Document> documents)
      Adds a list of documents to the vector store.
      Specified by:
      doAdd in class org.springframework.ai.vectorstore.observation.AbstractObservationVectorStore
      Parameters:
      documents - The list of documents to be added.
    • doDelete

      public void doDelete(List<String> documentIds)
      Deletes a list of documents by their IDs.
      Specified by:
      doDelete in class org.springframework.ai.vectorstore.observation.AbstractObservationVectorStore
      Parameters:
      documentIds - The list of document IDs to be deleted.
    • doDelete

      protected void doDelete(org.springframework.ai.vectorstore.filter.Filter.Expression filterExpression)
      Overrides:
      doDelete in class org.springframework.ai.vectorstore.observation.AbstractObservationVectorStore
    • doSimilaritySearch

      public List<org.springframework.ai.document.Document> doSimilaritySearch(org.springframework.ai.vectorstore.SearchRequest request)
      Performs a similarity search on the vector store.
      Specified by:
      doSimilaritySearch in class org.springframework.ai.vectorstore.observation.AbstractObservationVectorStore
      Parameters:
      request - The SearchRequest object containing the query and other search parameters.
      Returns:
      A list of documents that are similar to the query.
    • afterPropertiesSet

      public void afterPropertiesSet() throws Exception
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Throws:
      Exception
    • createObservationContextBuilder

      public org.springframework.ai.vectorstore.observation.VectorStoreObservationContext.Builder createObservationContextBuilder(String operationName)
      Specified by:
      createObservationContextBuilder in class org.springframework.ai.vectorstore.observation.AbstractObservationVectorStore
    • getNativeClient

      public <T> Optional<T> getNativeClient()
      Specified by:
      getNativeClient in interface org.springframework.ai.vectorstore.VectorStore