Retrieval
Find relevant information for agents
Agents can search and retrieve relevant information from your documents.
Quick Start
- 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 - With Configuration
typescript const agent = new Agent({ knowledge: { path: './docs/', strategy: 'semantic', // or 'keyword', 'hybrid' topK: 5 } });
User Interaction Flow
Configuration Levels
// 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
| Strategy | Best For |
|---|---|
keyword | Exact term matching |
semantic | Meaning-based search |
hybrid | Combines both approaches |
API Reference
KnowledgeConfigComplete configuration options
RAGRAG 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.