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

# Querying

> RAG and Structured Insights

Base URL: `http://localhost:8000/api/v1`

## RAG Query

Natural language queries against the user's memory.

```http theme={null}
POST /users/{user_id}/rag/query
Content-Type: application/json

{"query": "What projects am I working on?"}
```

**Response:**

```json theme={null}
{
    "query": "What projects am I working on?",
    "response": "Based on your memories, you're working on..."
}
```

## Ask (Structured Insights)

Get structured JSON responses by providing an output schema.

```http theme={null}
POST /users/{user_id}/ask
Content-Type: application/json

{
    "query": "What are my preferences?",
    "output_schema": {
        "preferences": ["example"],
        "summary": "string"
    }
}
```

**Response:**

```json theme={null}
{
    "result": {
        "preferences": ["remote work", "morning meetings"],
        "summary": "User prefers flexible work arrangements"
    }
}
```

## When to Use Which

| Use Case                 | Endpoint  |
| ------------------------ | --------- |
| Conversational responses | RAG Query |
| Data extraction for UI   | Ask       |
| Feature personalization  | Ask       |
| Chatbot augmentation     | RAG Query |

## Error Codes

| Code | Description                  |
| ---- | ---------------------------- |
| 400  | Bad Request - Invalid input  |
| 404  | User not found               |
| 500  | Internal server error        |
| 502  | External service (LLM) error |
| 503  | Database connection error    |
