Class SimpleKnowledge

java.lang.Object
io.agentscope.core.rag.knowledge.SimpleKnowledge
All Implemented Interfaces:
io.agentscope.core.rag.Knowledge

public class SimpleKnowledge extends Object implements 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();
 
  • Method Details

    • addDocuments

      public reactor.core.publisher.Mono<Void> addDocuments(List<io.agentscope.core.rag.model.Document> documents)
      Specified by:
      addDocuments in interface io.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:
      retrieve in interface io.agentscope.core.rag.Knowledge
    • getEmbeddingModel

      public EmbeddingModel getEmbeddingModel()
      Gets the embedding model used by this knowledge base.
      Returns:
      the embedding model
    • getEmbeddingStore

      public VDBStoreBase getEmbeddingStore()
      Gets the vector store used by this knowledge base.
      Returns:
      the vector store
    • builder

      public static SimpleKnowledge.Builder builder()
      Creates a new builder for SimpleKnowledge.
      Returns:
      a new Builder instance