Documentation

Retrieval QA Agent

The Retrieval QA Agent is a specialized component that enables intelligent question answering through document retrieval and analysis, providing accurate responses based on available knowledge sources.

Retrieval QA Agent Component

Retrieval QA Agent interface and configuration options

Configuration Parameters

Required Parameters

  • Language Model: The AI model for processing
  • Knowledge Base: Document collection source
  • Retriever Type: Document retrieval method
  • Index Type: Document indexing method
  • Embedding Model: Text embedding model

Optional Configuration

  • Retrieval Options: Search settings
    • topK: Number of documents
    • threshold: Similarity threshold
    • maxTokens: Token limit
  • Processing: Processing options
    • chunkSize: Document chunk size
    • overlap: Chunk overlap
    • preprocessing: Text preprocessing
  • Caching: Cache settings
    • enabled: Enable caching
    • ttl: Cache lifetime
    • maxSize: Cache size limit

Output Format

{
  "result": {
    "answer": {
      "text": string,
      "confidence": number
    },
    "context": {
      "documents": array,
      "relevance": array
    },
    "metadata": {
      "processingTime": string,
      "sourceCount": number,
      "tokenCount": number
    }
  }
}

Example Usage

const retrievalQAAgent = new RetrievalQAAgent({
  languageModel: "gpt-4",
  knowledgeBase: {
    source: "documents/",
    format: ["pdf", "txt", "md"]
  },
  retrieverType: "hybrid",
  indexType: "faiss",
  embeddingModel: "sentence-transformers/all-mpnet-base-v2",
  retrievalOptions: {
    topK: 5,
    threshold: 0.7,
    maxTokens: 1000
  },
  processing: {
    chunkSize: 500,
    overlap: 50,
    preprocessing: {
      removeStopwords: true,
      lowercase: true,
      stemming: true
    }
  },
  caching: {
    enabled: true,
    ttl: 3600,
    maxSize: "1GB"
  }
});

const result = await retrievalQAAgent.process({
  input: "What are the key features of our product?"
});

Best Practices

  • Optimize document chunking
  • Use appropriate embedding models
  • Configure retrieval thresholds
  • Implement efficient caching
  • Monitor retrieval performance