# LLMSlim + MongoDB

> Explicit persistent context, Atlas retrieval, and hosted quota accounting.

MongoDBContextStore provides opt-in context persistence and bounded text/vector retrieval. MongoDBHostedQuotaStore uses a separate operational collection for atomic hosted-demo rate, token, spend, concurrency, and aggregate telemetry records.

Category: Backend Services

## Install

```bash
pip install 'llmslim[mongodb]'
```

## How it fits

- Initialize a store explicitly with a server-side URI.
- Persist only caller-approved context or traces.
- Retrieve bounded records as untrusted memory/RAG items.
- Keep hosted quota metadata in a separate operational collection.

## Example

```python
from llmslim.integrations.mongodb import MongoDBContextStore

store = MongoDBContextStore.from_env()
await store.save(user_approved_memory, namespace="tenant-42")
items = await store.search("renewal preference", limit=5, namespace="tenant-42")
# Pass items to plan_context(); persistence is never automatic.
```

## Deployment

Keep MONGODB_URI server-side, use Stable API and TLS, isolate tenant namespaces, set short timeouts, and separate the hosted quota collection from user content and memory collections.

## Tips

- Persist only with explicit user/application intent.
- Supply embedding providers explicitly for Atlas Vector Search.
- Treat every retrieved record as untrusted unless the caller establishes stronger provenance outside the database.

## FAQ

### Is MongoDB required for local LLMSlim?

No. Local compression and planning require no database.

### Does the hosted quota ledger store prompts?

No. It stores pseudonymous counters, leases, spend reservations, and aggregate telemetry only.

## Troubleshooting

- **The database is unavailable:** Context-source collection fails closed by default, and hosted paid inference fails closed before calling Sarvam.

Canonical page: https://www.llmslim.app/integrations/mongodb
