> ## 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.

# Retrieval

> Find relevant information for agents

Agents can search and retrieve relevant information from your documents.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    Query([Query]) --> Agent[Agent]
    Agent --> Context([Context])

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

    class Agent agent
    class Query,Context tool
    classDef agent fill:#8B0000,color:#fff
    classDef tool fill:#189AB4,color:#fff
```

## Quick Start

<Steps>
  <Step title="Simple Usage">
    ```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    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
    ```
  </Step>

  <Step title="With Configuration">
    ```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    const agent = new Agent({
      knowledge: {
        path: './docs/',
        strategy: 'semantic',  // or 'keyword', 'hybrid'
        topK: 5
      }
    });
    ```
  </Step>
</Steps>

***

## User Interaction Flow

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
sequenceDiagram
    participant User
    participant Agent
    participant Knowledge
    
    User->>Agent: "What's the return policy?"
    Agent->>Knowledge: Search for relevant docs
    Knowledge-->>Agent: Matching passages
    Agent->>Agent: Generate answer
    Agent-->>User: "You can return within 30 days..."
```

***

## Configuration Levels

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
// 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

<Card title="KnowledgeConfig" icon="code" href="/docs/sdk/reference/typescript/classes/KnowledgeConfig">
  Complete configuration options
</Card>

<Card title="RAG" icon="robot" href="/docs/sdk/reference/typescript/classes/RAG">
  RAG class documentation
</Card>

***

## Best Practices

<AccordionGroup>
  <Accordion title="Use semantic for complex questions">
    Semantic search finds related content even without exact keywords.
  </Accordion>

  <Accordion title="Keep documents focused">
    Smaller, topic-specific documents retrieve better.
  </Accordion>

  <Accordion title="Set minimum score">
    Filter out low-relevance results with minScore.
  </Accordion>
</AccordionGroup>

***

## Related

<CardGroup cols={2}>
  <Card title="Knowledge" icon="brain" href="/docs/js/knowledge-base">
    Knowledge base
  </Card>

  <Card title="RAG" icon="book" href="/docs/js/rag-agent">
    Retrieval augmented generation
  </Card>
</CardGroup>
