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

# Context vs RAG Mode

> Choose between Context injection and RAG retrieval for your knowledge bases

export const Screenshot = ({lightSrc, darkSrc, alt, caption, maxWidth = "880px"}) => {
  return <div style={{
    margin: "1rem auto",
    maxWidth,
    width: "100%"
  }}>
      <Frame>
        <img className="block dark:hidden" src={lightSrc} alt={alt} />
        <img className="hidden dark:block" src={darkSrc} alt={alt} />
      </Frame>
      {caption ? <p style={{
    marginTop: "0.5rem",
    fontSize: "0.875rem",
    color: "inherit",
    opacity: 0.8
  }}>
          {caption}
        </p> : null}
    </div>;
};

## Two Access Methods

When you assign knowledge to your agent, you need to choose how the agent accesses that information. If you have not created a knowledge base yet, start with the [create knowledge bases](/build/knowledge/create-knowledge-bases) guide. itellicoAI offers two access methods: **Context Mode** (prompt injection) and **RAG Mode** (RAG: Retrieval-Augmented Generation — a search system that finds only the most relevant information your agent needs).

## Quick Decision

| Use Context When...                                    | Use RAG When...                                           |
| ------------------------------------------------------ | --------------------------------------------------------- |
| Content is small (under a few thousand words)          | Content is large (FAQs, catalogs, full documentation)     |
| Agent needs it on every single call                    | Agent only needs it for specific questions                |
| You want zero retrieval latency                        | You need broad coverage across many topics                |
| Examples: pricing table, business hours, return policy | Examples: product catalog, full FAQ library, support docs |

Not sure? **Start with RAG.** It's safer for most use cases. Switch to Context only for small, always-needed content.

***

## The Two Access Methods

<CardGroup cols={2}>
  <Card title="Context Mode" icon="file-import">
    **Prompt Injection**

    All knowledge is injected directly into the agent's conversation context (alongside your [prompt](/build/conversation/prompt)) at the start of each interaction.

    **Best for:** Small knowledge bases with critical information the agent needs for every conversation.
  </Card>

  <Card title="RAG Mode" icon="magnifying-glass">
    **RAG (Retrieval-Augmented Generation)**

    Agent dynamically searches and retrieves relevant knowledge based on the conversation topic.

    **Best for:** Larger knowledge bases where only specific sections are needed per conversation.
  </Card>
</CardGroup>

***

## Context Mode (Prompt Injection)

### How It Works

In Context Mode, the platform loads your knowledge base content directly into the agent's system prompt at the beginning of each conversation:

```text wrap theme={null}
System Prompt:
You are a helpful customer service agent.

[Your agent instructions...]

==== KNOWLEDGE BASE: Customer Support FAQ ====

### Billing & Payments
- Question: How do I update my payment method?
  Answer: You can update your payment method by...

- Question: When will I be billed?
  Answer: Billing occurs on the same day each month...

### Return Policy
[Full return policy content]

### Shipping Information
[Full shipping information]

==== END KNOWLEDGE BASE ====

Now assist the customer with their question.
```

The agent sees ALL knowledge content from the start and can reference it throughout the conversation.

### Formatted Output

By default, the system injects knowledge with structured formatting:

```text wrap theme={null}
========================================
# Knowledge Base Name
Knowledge base description

## Folder Name
Folder description

### Item Title
----------------------------------------
Item content here
----------------------------------------
========================================
```

This formatting helps the agent understand the structure and organization of the knowledge.

### When to Use Context Mode

<AccordionGroup>
  <Accordion title="Small, high-priority knowledge" icon="file">
    If your content is compact and the agent needs it on every call, Context Mode ensures it's always available.

    **Example use case:**
    A support agent with a knowledge base containing:

    * 10 common FAQs
    * Return policy
    * Contact information
    * Shipping options
  </Accordion>

  <Accordion title="Critical information needed every time" icon="circle-exclamation">
    Information the agent must reference on most or all calls.

    **Example use case:**
    A booking agent that needs:

    * Company policies (always)
    * Available services (always)
    * Pricing structure (always)
    * Booking procedures (always)
  </Accordion>

  <Accordion title="Highly structured information" icon="table">
    When knowledge items reference each other or form a cohesive whole.

    **Example use case:**
    Product configuration agent with:

    * Option dependencies ("If they choose X, offer Y")
    * Compatibility matrix
    * Package bundles
    * Pricing that depends on combinations
  </Accordion>
</AccordionGroup>

### Context Mode Advantages

<CardGroup cols={2}>
  <Card title="Always Available" icon="check">
    Access all knowledge immediately without search delay
  </Card>

  <Card title="Better for Small Sets" icon="gauge-high">
    Handle small knowledge sets efficiently within the context window
  </Card>

  <Card title="Deterministic" icon="equals">
    Deliver exactly the same knowledge every time
  </Card>

  <Card title="Works with Variables" icon="brackets-curly">
    Include Jinja variables that resolve at runtime
  </Card>
</CardGroup>

### Context Mode Limitations

<Warning>
  Context Mode is **limited to 10,000 tokens (roughly 7,500 words) total** across all assigned knowledge.
</Warning>

**Trade-offs:**

* All context-mode content is sent with every request, so more content means higher cost and latency
* The entire knowledge base is included even if only a small portion is relevant for that call
* Best for content that's a few thousand words or less — use RAG for anything larger

***

## RAG Mode (Retrieval-Augmented Generation)

### How It Works

In RAG Mode, the platform stores your knowledge base in a vector database. When the agent needs information:

1. **User asks a question:** "What's your return policy?"
2. **Agent identifies need:** Agent determines it needs knowledge about returns
3. **System searches:** RAG system searches knowledge base for relevant content
4. **Relevant content retrieved:** Only the return policy section is fetched
5. **Agent responds:** Agent uses retrieved knowledge to answer

The agent only sees the knowledge it needs, when it needs it.

### Intelligent Retrieval

RAG uses semantic search with vector embeddings to find relevant knowledge:

```text wrap theme={null}
User: "I need to send back the shoes I bought last week"

RAG System thinks:
- Keywords: "send back", "shoes", "bought"
- Semantic meaning: Returns, possibly exchange
- Search knowledge for: return policy, shipping, exchanges

Retrieved knowledge:
- Return Policy Overview
- Return Shipping Instructions
- Exchange Procedures

NOT retrieved:
- Billing FAQ
- Product Specifications
- Account Management
```

### RAG Mode Advantages

<CardGroup cols={2}>
  <Card title="Scales Beyond Context" icon="up-right-and-down-left-from-center">
    Support larger knowledge bases without the 10,000-token context limit
  </Card>

  <Card title="Faster for Large Knowledge" icon="clock-rotate-left">
    Reduces system prompt tokens for large knowledge bases
  </Card>

  <Card title="Efficient" icon="gauge-high">
    Only retrieves what's needed for current topic
  </Card>

  <Card title="Better for Diversity" icon="shapes">
    Handles wide variety of unrelated topics well
  </Card>
</CardGroup>

### RAG Mode Considerations

<Note>
  RAG relies on search accuracy. If your knowledge items aren't clearly written, retrieval may miss relevant information.
</Note>

**Retrieval quality depends on:**

* Clear, descriptive knowledge item titles
* Well-structured content
* Proper categorization into folders
* Avoiding duplicate or conflicting information

***

## Choosing the Right Mode

Use this decision guide to select the best access method:

### Hybrid Approach

You can use both modes for different knowledge bases on the same agent:

**Example configuration:**

* **Context Mode:** Small "Core Policies" knowledge base (always needed)
* **RAG Mode:** Large "Product Catalog" knowledge base (retrieve as needed)

This combines the strengths of both methods.

***

## Testing Your Configuration

<Steps>
  <Step title="Assign knowledge base">
    Configure your agent with a knowledge base in either Context or RAG Mode.
  </Step>

  <Step title="Start a test">
    Use the Test Agent menu to start a chat, web call, or phone call.
  </Step>

  <Step title="Ask about knowledge content">
    Ask questions that should be answered from your knowledge base.

    **Example questions:**

    * "What's your return policy?"
    * "How much does the Pro plan cost?"
    * "What are your business hours?"
  </Step>

  <Step title="Verify responses">
    Confirm the agent is correctly using knowledge content in responses.
  </Step>

  <Step title="Test edge cases">
    Ask about topics NOT in your knowledge base to ensure agent responds appropriately ("I don't have that information").
  </Step>
</Steps>

***

## Best Practices

<AccordionGroup>
  <Accordion title="Start with RAG for large bases" icon="magnifying-glass">
    When in doubt, use RAG Mode. It's safer for large knowledge bases and you can always switch to Context Mode if needed.
  </Accordion>

  <Accordion title="Write clear, complete content" icon="file-text">
    RAG uses semantic search to find relevant knowledge. Write complete, well-written content that naturally includes the terms and concepts users will ask about.

    **Good:** "Our return policy allows returns within 30 days of purchase for physical products. Digital products cannot be returned once downloaded."

    **Bad:** "See policy doc" or incomplete sentence fragments
  </Accordion>

  <Accordion title="Test both modes" icon="vial">
    Try both Context and RAG Mode with your knowledge base and see which performs better for your use case.
  </Accordion>

  <Accordion title="Combine strategically" icon="layer-group">
    Use Context Mode for critical, frequently-needed info and RAG Mode for extensive reference material.
  </Accordion>
</AccordionGroup>

***

## Troubleshooting

<AccordionGroup>
  <Accordion title="Agent isn't using knowledge (Context Mode)">
    **Check:**

    * Do all knowledge items show green (ready to use)?
    * Is remaining context sufficient (not truncated)?

    **Solution:**

    * Fix failed items
    * Reduce knowledge size or switch to RAG
  </Accordion>

  <Accordion title="Agent isn't finding knowledge (RAG Mode)">
    **Check:**

    * Is content well-organized?
    * Are you asking questions that match the knowledge?

    **Solution:**

    * Add more detailed content
    * Test with different phrasings
    * Consider adding keywords to content
  </Accordion>

  <Accordion title="Agent provides wrong or outdated information">
    **Check:**

    * Is the knowledge content correct and current?
    * Do you have conflicting information in multiple items?

    **Solution:**

    * Update knowledge content
    * Remove duplicates and conflicts
  </Accordion>

  <Accordion title="Context usage too high">
    **Solutions:**

    * Switch to RAG Mode for large knowledge bases
    * Split knowledge into smaller, focused bases
    * Reduce agent prompt length
    * Remove verbose or redundant content
  </Accordion>
</AccordionGroup>

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Create Knowledge Bases" icon="plus" href="/build/knowledge/create-knowledge-bases">
    Build and organize your knowledge content
  </Card>

  <Card title="Content Types" icon="file-lines" href="/build/knowledge/content-types">
    Learn about text, file, URL, and website crawl items
  </Card>

  <Card title="Template Syntax" icon="brackets-curly" href="/build/conversation/template-syntax">
    Use knowledge references in your prompt
  </Card>

  <Card title="Test Your Agent" icon="vial" href="/test/web-simulator">
    Test how your agent uses knowledge
  </Card>
</CardGroup>
