Documentation Index Fetch the complete documentation index at: https://docs.praison.ai/llms.txt
Use this file to discover all available pages before exploring further.
Automatically retrieve relevant context based on query analysis with AutoRagAgent.
Quick Start
Create AutoRagAgent
import { AutoRagAgent , RetrievalPolicy } from ' praisonai ' ;
const autoRag = new AutoRagAgent ({
retrievalPolicy : RetrievalPolicy . AUTO ,
topK : 5 ,
rerank : true
});
Check if Retrieval Needed
// Queries that trigger retrieval
autoRag . shouldRetrieve ( " What is machine learning? " ); // true
autoRag . shouldRetrieve ( " Explain the document " ); // true
autoRag . shouldRetrieve ( " Find information about AI " ); // true
// Queries that don't trigger retrieval
autoRag . shouldRetrieve ( " Hi " ); // false
autoRag . shouldRetrieve ( " Thanks " ); // false
Retrieval Policies
import { RetrievalPolicy } from ' praisonai ' ;
RetrievalPolicy . AUTO // Smart detection based on query
RetrievalPolicy . ALWAYS // Always retrieve context
RetrievalPolicy . NEVER // Never retrieve context
Configuration
import { AutoRagAgent , AutoRagAgentConfig , RetrievalPolicy } from ' praisonai ' ;
const config : AutoRagAgentConfig = {
retrievalPolicy : RetrievalPolicy . AUTO ,
topK : 5 , // Number of results to retrieve
hybrid : false , // Use hybrid search
rerank : true , // Rerank results
includeCitations : true , // Include citations in response
citationsMode : ' append ' , // 'append' | 'hidden' | 'none'
maxContextTokens : 4000 , // Max tokens for context
autoMinLength : 10 // Min query length for auto mode
};
const autoRag = new AutoRagAgent ( config );
Configuration Options
Option Type Default Description retrievalPolicyRetrievalPolicyAUTOWhen to retrieve context topKnumber5Number of results to retrieve hybridbooleanfalseUse hybrid (keyword + semantic) search rerankbooleanfalseRerank results for relevance includeCitationsbooleantrueInclude source citations citationsModestring'append'How to show citations maxContextTokensnumber4000Max context window autoMinLengthnumber10Min query length for AUTO
Auto Keywords
Queries containing these keywords trigger retrieval in AUTO mode:
import { DEFAULT_AUTO_KEYWORDS } from ' praisonai ' ;
// Default keywords that trigger retrieval
const keywords = [
' what ' , ' how ' , ' why ' , ' when ' , ' where ' , ' who ' , ' which ' ,
' explain ' , ' describe ' , ' summarize ' , ' find ' , ' search ' ,
' tell me ' , ' show me ' , ' according to ' , ' based on ' ,
' cite ' , ' source ' , ' reference ' , ' document ' , ' paper '
];
Custom Keywords
const autoRag = new AutoRagAgent ({
retrievalPolicy : RetrievalPolicy . AUTO ,
autoKeywords : new Set ([
' what ' , ' how ' , ' explain ' ,
' my custom keyword ' ,
' another trigger '
])
});
Methods
shouldRetrieve
Check if a query should trigger retrieval:
const autoRag = new AutoRagAgent ();
// Returns true for questions
autoRag . shouldRetrieve ( " What is the capital of France? " ); // true
// Returns true for search queries
autoRag . shouldRetrieve ( " Find documents about AI " ); // true
// Returns false for short queries
autoRag . shouldRetrieve ( " Hi " ); // false
// Returns false for non-question statements
autoRag . shouldRetrieve ( " Thanks for your help " ); // false
getConfig
Get the current configuration:
const config = autoRag . getConfig ();
console . log ( config . topK ); // 5
console . log ( config . retrievalPolicy ); // 'auto'
Common Patterns
With Knowledge Base
With Agent
import { AutoRagAgent , RetrievalPolicy , Knowledge } from ' praisonai ' ;
const knowledge = new Knowledge ({
sources : [ ' ./docs ' ],
embeddings : ' text-embedding-3-small '
});
const autoRag = new AutoRagAgent ({
retrievalPolicy : RetrievalPolicy . AUTO ,
topK : 5 ,
rerank : true
});
async function answer ( query : string ) {
if ( autoRag . shouldRetrieve ( query )) {
const context = await knowledge . search ( query , { topK : 5 });
return generateWithContext ( query , context );
}
return generateDirect ( query );
}
import { Agent , AutoRagAgent , RetrievalPolicy } from ' praisonai ' ;
const autoRag = new AutoRagAgent ({
retrievalPolicy : RetrievalPolicy . AUTO
});
const agent = new Agent ({
name : " RAG Assistant " ,
instructions : " Answer questions using retrieved context "
});
async function chat ( query : string ) {
const needsContext = autoRag . shouldRetrieve ( query );
if ( needsContext ) {
// Add context to the query
const context = await retrieveContext ( query );
return agent . start ( ` Context: ${ context } \n\n Question: ${ query } ` );
}
return agent . start ( query );
}
API Reference
AutoRagAgent AutoRagAgent class reference
AutoRagAgentConfig Configuration options
Best Practices
Use AUTO for general chatbots
AUTO mode balances retrieval costs with response quality for most use cases.
Use ALWAYS for document Q&A
When every query relates to documents, use ALWAYS to ensure context is included.
Enable reranking for accuracy
Reranking improves result relevance at a small latency cost.
Increase autoMinLength to avoid retrieval for very short queries.
RAG Agent Full RAG implementation
Knowledge Base Build knowledge bases