Package io.agentscope.core.rag.knowledge
Class SimpleKnowledge
java.lang.Object
io.agentscope.core.rag.knowledge.SimpleKnowledge
- All Implemented Interfaces:
io.agentscope.core.rag.Knowledge
Simple implementation of a knowledge base.
This implementation integrates an embedding model and a vector store to provide a complete RAG (Retrieval-Augmented Generation) knowledge base. It handles the full workflow: document embedding, storage, and retrieval.
Workflow:
- addDocuments: Embed documents → Store documents (with metadata/payload) in vector store
- retrieve: Embed query → Search documents → Filter by threshold → Return documents
Example usage:
EmbeddingModel embeddingModel = DashScopeTextEmbedding.builder()
.apiKey(apiKey)
.modelName("text-embedding-v3")
.dimensions(1024)
.build();
VDBStoreBase vectorStore = InMemoryStore.builder().dimensions(1024).build();
SimpleKnowledge knowledge = SimpleKnowledge.builder()
.embeddingModel(embeddingModel)
.embeddingStore(vectorStore)
.build();
// Add documents
List<Document> documents = reader.read(input).block();
knowledge.addDocuments(documents).block();
// Retrieve documents
RetrieveConfig config = RetrieveConfig.builder().limit(5).scoreThreshold(0.5).build();
List<Document> results = knowledge.retrieve("query text", config).block();
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for SimpleKnowledge. -
Method Summary
Modifier and TypeMethodDescriptionreactor.core.publisher.Mono<Void>addDocuments(List<io.agentscope.core.rag.model.Document> documents) static SimpleKnowledge.Builderbuilder()Creates a new builder for SimpleKnowledge.Gets the embedding model used by this knowledge base.Gets the vector store used by this knowledge base.reactor.core.publisher.Mono<List<io.agentscope.core.rag.model.Document>>
-
Method Details
-
addDocuments
public reactor.core.publisher.Mono<Void> addDocuments(List<io.agentscope.core.rag.model.Document> documents) - Specified by:
addDocumentsin interfaceio.agentscope.core.rag.Knowledge
-
retrieve
public reactor.core.publisher.Mono<List<io.agentscope.core.rag.model.Document>> retrieve(String query, io.agentscope.core.rag.model.RetrieveConfig config) - Specified by:
retrievein interfaceio.agentscope.core.rag.Knowledge
-
getEmbeddingModel
Gets the embedding model used by this knowledge base.- Returns:
- the embedding model
-
getEmbeddingStore
Gets the vector store used by this knowledge base.- Returns:
- the vector store
-
builder
Creates a new builder for SimpleKnowledge.- Returns:
- a new Builder instance
-