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

# Azure Cosmos DB

> Azure Cosmos DB vector store for PraisonAI

# Azure Cosmos DB

Globally distributed, multi-model database with vector search capabilities.

## Setup

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# For MongoDB API
pip install pymongo

# For SQL API
pip install azure-cosmos
```

## Quick Start (Agent with Knowledge)

Use Azure Cosmos DB as a knowledge store with an agent:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent
import os

agent = Agent(
    name="Assistant",
    instructions="You are a helpful assistant with access to documents.",
    knowledge=["./docs/guide.pdf"]
)

agent.chat("What does the guide say?")
```

## Advanced Usage (Direct Store)

### MongoDB API (Recommended for Vector Search)

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonai.persistence.factory import create_knowledge_store

store = create_knowledge_store(
    "cosmosdb",
    connection_string="mongodb+srv://...",
    database="praisonai",
    collection="vectors",
    api_mode="mongodb"
)
```

### SQL API

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
store = create_knowledge_store(
    "cosmosdb",
    connection_string="AccountEndpoint=...",
    database="praisonai",
    collection="vectors",
    api_mode="sql"
)
```

## Environment Variables

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
export COSMOS_CONNECTION_STRING="mongodb+srv://..."
```

## Configuration

| Option              | Description                         |
| ------------------- | ----------------------------------- |
| `connection_string` | Azure Cosmos DB connection string   |
| `database`          | Database name                       |
| `collection`        | Collection/container name           |
| `api_mode`          | `mongodb` or `sql`                  |
| `index_name`        | Vector index name                   |
| `embedding_dim`     | Embedding dimension (default: 1536) |

## Vector Search Setup

For MongoDB API, create a vector search index:

```javascript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
db.runCommand({
  createIndexes: "vectors",
  indexes: [{
    name: "vector_index",
    key: { embedding: "cosmosSearch" },
    cosmosSearchOptions: {
      kind: "vector-ivf",
      numLists: 100,
      similarity: "cosine",
      dimensions: 1536
    }
  }]
})
```

## Best For

* Global distribution requirements
* Multi-region deployments
* Azure ecosystem integration
