Skip to main content
Back to integrations
Backend ServicesMemory & retrieval

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.

1. Package installation

Install LLMSlim and the official MongoDB SDK using your package manager.

terminalbash
pip install 'llmslim[mongodb]'

2. Architecture & execution flow

1

Initialize a store explicitly with a server-side URI.

2

Persist only caller-approved context or traces.

3

Retrieve bounded records as untrusted memory/RAG items.

4

Keep hosted quota metadata in a separate operational collection.

3. Production code pattern

mongodb_memory.pypython
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.

4. Deployment best practices

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.

5. Key optimization 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.

Frequently asked questions

Troubleshooting