> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# RAG Agent

> Build Retrieval-Augmented Generation agents with knowledge bases

Build agents that retrieve and cite information from knowledge bases.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    User([User]) --> Agent[RAG Agent]
    Agent --> KB([Knowledge Base])
    KB --> Response([Response])

    classDef agent fill:#8B0000,stroke:#7C90A0,color:#fff
    classDef tool fill:#189AB4,stroke:#7C90A0,color:#fff

    class Agent agent
    class User,KB,Response tool
    classDef agent fill:#8B0000,color:#fff
    classDef tool fill:#189AB4,color:#fff
```

## Quick Start

**1. Simple Usage**

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import { Agent, createMemoryVectorStore } from 'praisonai-ts';

// Create a vector store for RAG
const vectorStore = createMemoryVectorStore();

// Add documents to the knowledge base
await vectorStore.addDocuments([
  { id: '1', content: 'PraisonAI is an AI agent framework', metadata: { source: 'docs' } },
  { id: '2', content: 'Agents can use tools to accomplish tasks', metadata: { source: 'docs' } },
]);

// Create an agent with RAG capabilities
const agent = new Agent({
  name: 'RAGAgent',
  instructions: 'You answer questions using the knowledge base. Always cite sources.',
  knowledge: vectorStore,
});

const response = await agent.chat('What is PraisonAI?');
console.log(response);
```

**2. With Configuration**

Use `ragConfig`, production vector stores, and reranking — see Configuration Options below.

## Configuration Options

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import { Agent, createPineconeStore } from 'praisonai-ts';

const vectorStore = await createPineconeStore({
  apiKey: process.env.PINECONE_API_KEY!,
  index: 'my-knowledge-base',
  namespace: 'docs',
});

const agent = new Agent({
  name: 'RAGAgent',
  instructions: 'You are a helpful assistant with access to a knowledge base.',
  knowledge: vectorStore,
  ragConfig: {
    topK: 5,                    // Number of results to retrieve
    minScore: 0.7,              // Minimum similarity score
    includeMetadata: true,      // Include document metadata
    rerank: true,               // Enable reranking
    citationFormat: 'inline',   // Citation format: inline, footnote, none
  },
});
```

## Vector Store Options

### Memory Vector Store (Development)

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import { createMemoryVectorStore } from 'praisonai-ts';

const store = createMemoryVectorStore();
```

### Pinecone

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import { createPineconeStore } from 'praisonai-ts';

const store = await createPineconeStore({
  apiKey: process.env.PINECONE_API_KEY!,
  index: 'my-index',
  namespace: 'my-namespace',
});
```

### Weaviate

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import { createWeaviateStore } from 'praisonai-ts';

const store = await createWeaviateStore({
  host: process.env.WEAVIATE_HOST!,
  apiKey: process.env.WEAVIATE_API_KEY,
  className: 'Documents',
});
```

### Qdrant

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import { createQdrantStore } from 'praisonai-ts';

const store = await createQdrantStore({
  url: process.env.QDRANT_URL!,
  apiKey: process.env.QDRANT_API_KEY,
  collectionName: 'my-collection',
});
```

### ChromaDB

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import { createChromaStore } from 'praisonai-ts';

const store = await createChromaStore({
  path: './chroma-data',
  collectionName: 'my-collection',
});
```

## Adding Documents

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
// Add single document
await vectorStore.addDocument({
  id: 'doc-1',
  content: 'Document content here',
  metadata: { source: 'manual', category: 'guide' },
});

// Add multiple documents
await vectorStore.addDocuments([
  { id: 'doc-2', content: 'First document', metadata: {} },
  { id: 'doc-3', content: 'Second document', metadata: {} },
]);

// Add from file (PDF, TXT, MD)
await vectorStore.addFromFile('./document.pdf');
```

## Reranking

Enable reranking for better retrieval quality:

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import { Agent, createCohereReranker } from 'praisonai-ts';

const reranker = createCohereReranker({
  apiKey: process.env.COHERE_API_KEY!,
  model: 'rerank-english-v3.0',
});

const agent = new Agent({
  name: 'RAGAgent',
  instructions: 'Answer questions using the knowledge base.',
  knowledge: vectorStore,
  reranker: reranker,
});
```

## Graph RAG

For complex relationships between documents:

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import { createGraphRAG } from 'praisonai-ts';

const graphRAG = await createGraphRAG({
  vectorStore: vectorStore,
  extractEntities: true,
  extractRelationships: true,
});

const agent = new Agent({
  name: 'GraphRAGAgent',
  instructions: 'Answer questions using the knowledge graph.',
  knowledge: graphRAG,
});
```

## Best Practices

> [accordion] Chunk documents appropriately
>
> Split large documents into meaningful chunks.

> [accordion] Use metadata
>
> Add source, date, and category metadata for filtering.

> [accordion] Enable reranking
>
> Improves retrieval quality for complex queries.

> [accordion] Set appropriate topK
>
> Balance between context size and relevance.

## Environment Variables

| Variable | Required | Description |
| - | - | - |
| `OPENAI_API_KEY` | Yes | For embeddings and LLM |
| `PINECONE_API_KEY` | For Pinecone | Pinecone API key |
| `COHERE_API_KEY` | For reranking | Cohere API key |

## Related

> [card] [Knowledge Base](https://praison.ai/docs/js/knowledge-base.md)
>
> Managing knowledge bases

> [card] [Graph RAG](https://praison.ai/docs/js/graph-rag.md)
>
> Graph-based RAG


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.