Retrieval

Find relevant information for agents

Agents can search and retrieve relevant information from your documents.

Diagram

Query

Agent

Context

Quick Start

  1. Simple Usage
    typescript
    import { Agent } from 'praisonai';
    
    const agent = new Agent({
      instructions: 'Answer questions using the provided documents',
      knowledge: './docs/'  // Folder of documents
    });
    
    await agent.chat('What is the return policy?');
    // Agent searches docs and answers accurately
  2. With Configuration
    typescript
    const agent = new Agent({
      knowledge: {
        path: './docs/',
        strategy: 'semantic',  // or 'keyword', 'hybrid'
        topK: 5
      }
    });

User Interaction Flow

Diagram
KnowledgeAgentUserKnowledgeAgentUser“What’s the return policy?”Search for relevant docsMatching passagesGenerate answer“You can return within 30 days…”

Configuration Levels

typescript
// Level 1: String - Path to documents
const agent = new Agent({
  knowledge: './docs/'
});

// Level 2: Array - Multiple sources
const agent = new Agent({
  knowledge: ['./policies/', './faq/', './guides/']
});

// Level 3: Dict - Full options
const agent = new Agent({
  knowledge: {
    path: './docs/',
    strategy: 'hybrid',
    topK: 10,
    minScore: 0.7,
    chunkSize: 500
  }
});

Retrieval Strategies

StrategyBest For
keywordExact term matching
semanticMeaning-based search
hybridCombines both approaches

API Reference

KnowledgeConfig

Complete configuration options

RAG

RAG class documentation


Best Practices

Use semantic for complex questions

Semantic search finds related content even without exact keywords.

Keep documents focused

Smaller, topic-specific documents retrieve better.

Set minimum score

Filter out low-relevance results with minScore.


Related