Class RAGFlowKnowledge

java.lang.Object
io.agentscope.core.rag.integration.ragflow.RAGFlowKnowledge
All Implemented Interfaces:
io.agentscope.core.rag.Knowledge

public class RAGFlowKnowledge extends Object implements io.agentscope.core.rag.Knowledge
RAGFlow Knowledge Base implementation.

This class provides integration with RAGFlow Knowledge Base service, implementing the Knowledge interface to enable seamless RAG (Retrieval-Augmented Generation) capabilities with RAGFlow-hosted knowledge bases.

Key features:

  • Local or remote RAGFlow deployment support
  • Advanced document understanding with OCR
  • Knowledge graph enhanced retrieval
  • Reranking support for better results
  • Conversation history support for context-aware retrieval
  • Compatible with Bailian and Dify RAG plugins (same Knowledge interface)

Functional Scope: This plugin focuses on retrieval capabilities only, similar to Bailian and Dify RAG plugins. Document management (upload/delete/update) should be performed via RAGFlow console.

Example usage:


 RAGFlowConfig config = RAGFlowConfig.builder()
     .apiKey("ragflow-xxx")
     .baseUrl("http://localhost:9380")
     .knowledgeBaseId("kb-xxx")
     .topK(10)
     .similarityThreshold(0.5)
     .enableRerank(true)
     .build();

 RAGFlowKnowledge knowledge = RAGFlowKnowledge.builder()
     .config(config)
     .build();

 // Retrieve documents
 List<Document> docs = knowledge.retrieve("What is AI?", retrieveConfig).block();

 // Use with Agent
 ReActAgent agent = ReActAgent.builder()
     .knowledge(knowledge)
     .ragMode(RAGMode.AGENTIC)
     .build();
 

Note: Document management is not supported via this plugin. Please use RAGFlow console to upload, delete, and manage documents. This design ensures compatibility with Bailian and Dify RAG plugins and keeps the plugin focused.

Author:
RAGFlow Integration Team
  • Method Details

    • builder

      public static RAGFlowKnowledge.Builder builder()
    • retrieve

      public reactor.core.publisher.Mono<List<io.agentscope.core.rag.model.Document>> retrieve(String query, io.agentscope.core.rag.model.RetrieveConfig config)
      Retrieve documents from the RAGFlow knowledge base.

      This method searches the RAGFlow dataset for documents relevant to the given query. The RAGFlow retrieve-chunks API is used under the hood.

      API Endpoint: POST /api/v1/datasets/{dataset_id}/retrieve-chunks

      Features:

      • Vector similarity search
      • Configurable top-K results
      • Similarity threshold filtering
      • Metadata-based filtering (via config)

      Note: Unlike some other RAG systems, RAGFlow's retrieve-chunks API does not support:

      • ❌ Conversation history for context-aware retrieval
      Specified by:
      retrieve in interface io.agentscope.core.rag.Knowledge
      Parameters:
      query - the query text (required)
      config - the retrieval configuration (limit, score threshold)
      Returns:
      a Mono emitting the list of retrieved documents, sorted by relevance
    • addDocuments

      public reactor.core.publisher.Mono<Void> addDocuments(List<io.agentscope.core.rag.model.Document> documents)
      Adds documents to the knowledge base.

      Note: This operation is not supported, consistent with Bailian and Dify RAG plugins. Document management should be performed via RAGFlow console:

      1. Access RAGFlow console (http://localhost:9380)
      2. Navigate to Knowledge Base > Select your dataset
      3. Click "Upload Document" to add files
      4. Wait for processing to complete
      5. Documents will be available for retrieval via this plugin
      Specified by:
      addDocuments in interface io.agentscope.core.rag.Knowledge
      Parameters:
      documents - the list of documents to add
      Returns:
      a Mono that completes with an error indicating the operation is not supported