Package io.agentscope.core.rag.store
Class ElasticsearchStore
java.lang.Object
io.agentscope.core.rag.store.ElasticsearchStore
- All Implemented Interfaces:
VDBStoreBase,AutoCloseable
Elasticsearch vector database store implementation.
This class provides an interface for storing and searching vectors using Elasticsearch.
It uses the official elasticsearch-java client.
The implementation uses the dense_vector field type for storing embeddings and
kNN search for retrieval.
Example usage:
// Using builder with authentication
try (ElasticsearchStore store = ElasticsearchStore.builder()
.url("http://localhost:9200")
.indexName("my_rag_index")
.dimensions(1024)
.username("elastic")
.password("changeme")
.build()) {
store.add(document).block();
List<Document> results = store.search(queryEmbedding, 5, 0.7).block();
}
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for ElasticsearchStore. -
Method Summary
Modifier and TypeMethodDescriptionreactor.core.publisher.Mono<Void>Adds a list of documents to the Elasticsearch index.static ElasticsearchStore.Builderbuilder()Creates a new builder for ElasticsearchStore.voidclose()reactor.core.publisher.Mono<Boolean>Deletes a document from the Elasticsearch index by its ID.reactor.core.publisher.Mono<List<io.agentscope.core.rag.model.Document>>search(SearchDocumentDto searchDocumentDto) Searches for documents in the Elasticsearch index matching the query embedding.
-
Method Details
-
add
Adds a list of documents to the Elasticsearch index.- Specified by:
addin interfaceVDBStoreBase- Parameters:
documents- the list of documents to add- Returns:
- a Mono that completes when the operation is finished
-
search
public reactor.core.publisher.Mono<List<io.agentscope.core.rag.model.Document>> search(SearchDocumentDto searchDocumentDto) Searches for documents in the Elasticsearch index matching the query embedding.- Specified by:
searchin interfaceVDBStoreBase- Parameters:
searchDocumentDto- the search criteria containing query embedding, limit, and score threshold- Returns:
- a Mono containing the list of matching documents
-
delete
Deletes a document from the Elasticsearch index by its ID.- Specified by:
deletein interfaceVDBStoreBase- Parameters:
id- the ID of the document to delete- Returns:
- a Mono containing true if the document was deleted, false if not found
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
builder
Creates a new builder for ElasticsearchStore.- Returns:
- a new Builder instance
-