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

# Multi-Source Lookups

> Query across multiple documents for comprehensive answers

<Info>
  **Time:** 15 minutes | **Level:** Advanced\
  **Prerequisites:** [Knowledge Base Fundamentals](/tutorials/advanced/knowledge-base-fundamentals)
</Info>

## What You'll Learn

* Uploading multiple related documents
* Cross-document querying
* Handling conflicting data
* Building comprehensive lookup systems
* Use cases for multi-source knowledge

***

## Why Multiple Sources?

Real businesses have data spread across multiple documents:

| Document Type    | Contains                    |
| ---------------- | --------------------------- |
| Product catalog  | Names, descriptions, SKUs   |
| Price list       | Current pricing, tiers      |
| Shipping rates   | Delivery costs, zones       |
| Inventory sheet  | Stock levels, availability  |
| Supplier catalog | Wholesale costs, lead times |

Multi-source lookups let you query all of these simultaneously.

***

## Setting Up Multiple Documents

<Steps>
  <Step title="Upload Related Documents">
    Add each document to your Knowledge Base:

    * **Product Catalog.pdf** - item descriptions
    * **Price List Q1 2024.xlsx** - current pricing
    * **Shipping Zones.pdf** - delivery rates

    Each processes independently.
  </Step>

  <Step title="Verify Extractions">
    Check that each document extracted correctly:

    * Product names should be consistent across documents
    * SKUs or IDs should match where applicable
    * Dates should be recognized for version tracking
  </Step>

  <Step title="Note Common Identifiers">
    Identify how documents relate:

    * Product names (must match exactly)
    * SKU/Item codes
    * Category names

    These act as "keys" linking data across sources.
  </Step>
</Steps>

***

## Cross-Document Queries

Ask questions that span multiple documents:

<Tabs>
  <Tab title="Combined Lookups">
    Pull data from multiple sources in one query:

    ```
    "What's the price, description, and shipping cost 
     for Product X to Zone 3?"
    ```

    Peanuts searches:

    * Product catalog → description
    * Price list → unit price
    * Shipping zones → delivery cost

    Returns a unified answer.
  </Tab>

  <Tab title="Comparison Queries">
    Compare data across document versions:

    ```
    "How has the price of Widget A changed between 
     Q4 2023 and Q1 2024 price lists?"
    ```

    Both versions must be uploaded with clear date identifiers.
  </Tab>

  <Tab title="Aggregation Queries">
    Calculate totals using multiple sources:

    ```
    "Calculate the total cost for 50 units of Product Y 
     including shipping to California"
    ```

    Combines unit price × quantity + shipping rate.
  </Tab>

  <Tab title="Availability Queries">
    Check across catalog and inventory:

    ```
    "Which items from the Premium Collection are 
     currently in stock with more than 20 units?"
    ```

    Cross-references catalog (collection) with inventory (stock levels).
  </Tab>
</Tabs>

***

## Handling Data Conflicts

When documents contain overlapping or conflicting data:

<AccordionGroup>
  <Accordion title="Version Priority" icon="clock-rotate-left">
    **Scenario:** Multiple price lists with different dates

    **Solution:** Peanuts uses the most recent document by default. You can specify:

    ```
    "What was the price in the Q3 2023 price list?"
    ```

    Explicitly references the older version.
  </Accordion>

  <Accordion title="Source Specification" icon="file-circle-check">
    **Scenario:** Same product name, different catalogs

    **Solution:** Specify the source:

    ```
    "What's the price from the Wholesale Catalog 
     (not the Retail Price List)?"
    ```
  </Accordion>

  <Accordion title="Conflict Reporting" icon="triangle-exclamation">
    **Scenario:** Two documents show different prices

    **Behavior:** Peanuts flags the conflict:

    > "I found two prices for Widget X:
    >
    > * Retail Price List: \$49.99
    > * Promotional Flyer: \$39.99
    >
    > Which should I use?"
  </Accordion>

  <Accordion title="Default Source Setting" icon="gear">
    **Scenario:** One source should always take priority

    **Solution:** In Knowledge settings, set document priority order. Higher priority sources override lower ones.
  </Accordion>
</AccordionGroup>

***

## Linking to Helpers

Connect multiple knowledge sources to a single helper:

<Steps>
  <Step title="Open Helper Settings">
    Go to your helper → **Settings** → **Knowledge**.
  </Step>

  <Step title="Select Multiple Documents">
    Check all relevant documents:

    * ☑ Product Catalog
    * ☑ Current Price List
    * ☑ Shipping Rates
    * ☑ Inventory Status
  </Step>

  <Step title="Set Priority (Optional)">
    Drag to reorder if certain sources should take precedence.
  </Step>

  <Step title="Test Combined Queries">
    In the helper, ask questions that require multiple sources:

    ```
    "Create a quote for 100 units of Item SKU-4521 
     shipped to Zone 2"
    ```
  </Step>
</Steps>

***

## Use Case: Complete Order System

Build a helper that uses 4+ knowledge sources:

```mermaid theme={null}
graph LR
    A[Customer Request] --> B[Helper]
    B --> C[Product Catalog]
    B --> D[Price List]
    B --> E[Inventory]
    B --> F[Shipping Rates]
    C --> G[Full Quote]
    D --> G
    E --> G
    F --> G
```

**Query flow:**

1. Customer asks for a quote
2. Helper checks product exists (catalog)
3. Looks up current price (price list)
4. Verifies availability (inventory)
5. Calculates shipping (shipping rates)
6. Returns complete quote with all details

***

## Organizing Large Knowledge Bases

<CardGroup cols={2}>
  <Card title="By Category" icon="folder">
    Group related documents:

    * Products/
    * Pricing/
    * Logistics/
    * Policies/
  </Card>

  <Card title="By Version" icon="code-branch">
    Track document versions:

    * Price List v1 (Jan 2024)
    * Price List v2 (Apr 2024)
    * Price List v3 (Jul 2024)
  </Card>

  <Card title="By Client" icon="users">
    Separate client-specific data:

    * Client A Rates
    * Client B Rates
    * Standard Rates
  </Card>

  <Card title="By Region" icon="globe">
    Geographic separation:

    * US Pricing
    * EU Pricing
    * APAC Pricing
  </Card>
</CardGroup>

***

## Best Practices

<Tip>
  **Naming Conventions:** Use consistent, descriptive file names that include:

  * Document type
  * Version or date
  * Scope (region, client, etc.)

  Example: `Retail-Price-List_Q1-2024_US.pdf`
</Tip>

<Warning>
  **Avoid:** Uploading dozens of tiny documents. Combine related data when possible—too many sources increases query time and potential for conflicts.
</Warning>

***

## Exercise

<Card title="Practice: Build a Multi-Source Quote System" icon="dumbbell">
  Create a system using at least 3 knowledge sources:

  1. **Create 3 sample documents:**
     * Product list (5+ items with names/descriptions)
     * Price list (matching products with prices)
     * Shipping rates (3+ zones with costs)

  2. **Upload all three to Knowledge Base**

  3. **Create a "Quote Generator" helper** linked to all sources

  4. **Test these queries:**
     * "What's the total for \[product] shipped to \[zone]?"
     * "Which products are under \$50?"
     * "What's the cheapest shipping option for \[product]?"

  5. **Intentionally create a conflict** (same product, different price in two docs) and see how it's handled

  **Success:** All queries return accurate, combined data from multiple sources.
</Card>

***

## Key Takeaways

<Tip>
  **Remember:** Multi-source lookups are like having a smart assistant who knows where everything is filed. Upload your documents, maintain consistent naming, and let Peanuts connect the dots across all your data.
</Tip>

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Scheduled Reports" href="/tutorials/advanced/scheduled-reports" icon="calendar-check">
    Automate insights from your knowledge
  </Card>

  <Card title="Webhooks & Automation" href="/tutorials/expert/webhooks-and-automations" icon="webhook">
    Trigger actions when knowledge is queried
  </Card>
</CardGroup>
