Class QdrantStore
- All Implemented Interfaces:
VDBStoreBase,AutoCloseable
This class provides an interface for storing and searching vectors using Qdrant, a production-ready vector database. It implements the VDBStoreBase interface to provide a unified API for vector storage operations.
In Qdrant, we use the payload field to store the metadata, including the document ID, chunk ID, and original content.
This implementation uses the Qdrant Java SDK (io.qdrant:client). To use this class, add the following dependency:
<dependency>
<groupId>io.qdrant</groupId>
<artifactId>client</artifactId>
<version>1.15.0</version>
<scope>provided</scope>
</dependency>
Example usage:
// Using builder with TLS and compatibility options (recommended)
try (QdrantStore store = QdrantStore.builder()
.location("http://localhost:6333")
.collectionName("my_collection")
.dimensions(1024)
.apiKey("my-api-key")
.useTransportLayerSecurity(true)
.checkCompatibility(false)
.build()) {
store.add(document).block();
List<Document> results = store.search(queryEmbedding, 5).block();
// Store is automatically closed here
}
// Using static factory method (simpler, uses defaults)
try (QdrantStore store = QdrantStore.create("http://localhost:6333", "my_collection", 1024)) {
store.add(document).block();
List<Document> results = store.search(queryEmbedding, 5).block();
}
Note: The location parameter can be:
- HTTP URL: "http://localhost:6333" - will use gRPC on port 6334
- gRPC URL: "localhost:6334" - direct gRPC connection
- Local path: "file:///path/to/qdrant" - local Qdrant instance
- Memory mode: ":memory:" - in-memory Qdrant (requires local Qdrant)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for creating QdrantStore instances with fluent configuration. -
Method Summary
Modifier and TypeMethodDescriptionreactor.core.publisher.Mono<Void>Adds multiple documents to the store.static QdrantStore.Builderbuilder()Creates a new builder for constructing QdrantStore instances.voidclose()Closes the Qdrant client and releases all resources.reactor.core.publisher.Mono<Boolean>Deletes a document from the store (optional).Gets the API key (if set).io.qdrant.client.QdrantClientGets the underlying Qdrant client for advanced operations.Gets the collection name.intGets the vector dimensions.io.qdrant.client.QdrantGrpcClientGets the underlying gRPC client for low-level operations.Gets the Qdrant server location.booleanisClosed()Checks if this store has been closed.reactor.core.publisher.Mono<List<io.agentscope.core.rag.model.Document>>search(SearchDocumentDto searchDocumentDto) Searches for similar documents.
-
Method Details
-
add
Description copied from interface:VDBStoreBaseAdds multiple documents to the store.All documents must have embedding vectors set. The store will persist both the vectors and the document metadata/payloads.
This method supports batch operations for efficiency. Implementations should handle batch insertion optimally.
- Specified by:
addin interfaceVDBStoreBase- Parameters:
documents- the list of documents to store (all must have embeddings set)- Returns:
- a Mono that completes when all documents are stored
-
search
public reactor.core.publisher.Mono<List<io.agentscope.core.rag.model.Document>> search(SearchDocumentDto searchDocumentDto) Description copied from interface:VDBStoreBaseSearches for similar documents.This method performs vector similarity search and returns the most similar documents. Results include the document metadata and similarity scores. Optionally, embeddings may also be included in the results (implementation-dependent).
- Specified by:
searchin interfaceVDBStoreBase- Parameters:
searchDocumentDto- the search document DTO- Returns:
- a Mono that emits a list of Document objects with scores set, sorted by similarity (descending)
-
delete
Description copied from interface:VDBStoreBaseDeletes a document from the store (optional).Default implementation throws UnsupportedOperationException. Vector stores that support deletion should override this method.
- Specified by:
deletein interfaceVDBStoreBase- Parameters:
id- the document ID (UUID string) to delete- Returns:
- a Mono that emits true if the deletion was successful, false otherwise
-
getClient
Gets the underlying Qdrant client for advanced operations.This method provides access to the Qdrant client for users who need to perform operations beyond the standard VDBStoreBase interface, such as:
- Custom index configuration
- Advanced filtering and faceting
- Collection management
- Batch operations
- Returns:
- the QdrantClient instance
- Throws:
VectorStoreException- if the store has been closed
-
getGrpcClient
Gets the underlying gRPC client for low-level operations.This provides direct access to the gRPC client for advanced users who need maximum control over Qdrant operations.
- Returns:
- the QdrantGrpcClient instance
- Throws:
VectorStoreException- if the store has been closed
-
getLocation
Gets the Qdrant server location.- Returns:
- the location
-
getCollectionName
Gets the collection name.- Returns:
- the collection name
-
getDimensions
public int getDimensions()Gets the vector dimensions.- Returns:
- the dimensions
-
getApiKey
Gets the API key (if set).- Returns:
- the API key, or null if not set
-
close
public void close()Closes the Qdrant client and releases all resources.This method closes both the QdrantClient and the underlying QdrantGrpcClient, releasing all gRPC connections and associated resources. This method is idempotent and can be called multiple times safely.
After closing, all operations on this store will fail with a VectorStoreException. It's recommended to use try-with-resources for automatic resource management:
try (QdrantStore store = new QdrantStore("http://localhost:6333", "collection", 1024)) { store.add(1L, embedding).block(); // Store is automatically closed here }- Specified by:
closein interfaceAutoCloseable
-
isClosed
public boolean isClosed()Checks if this store has been closed.- Returns:
- true if the store has been closed, false otherwise
-
builder
Creates a new builder for constructing QdrantStore instances.- Returns:
- a new builder instance
-