Skip to main content

LlamaIndex Chat Store Integration: MongoDB Chat Store

Installation

pip install llama-index-storage-chat-store-mongodb

Usage

Using MongoChatStore from llama_index.storage.chat_store.mongo you can store chat history in MongoDB.

from llama_index.storage.chat_store.mongo import MongoChatStore

# Initialize the MongoDB chat store with URI and database name and collection name
chat_store = MongoChatStore(
    mongodb_uri="mongodb://localhost:27017/",
    db_name="llama_index",
    collection_name="chat_sessions",
)

You can also initialize the chat store with a MongoClient or AsyncMongoClient and a database name and collection name.

from pymongo import MongoClient, AsyncMongoClient

client = MongoClient("mongodb://localhost:27017/")
async_client = AsyncMongoClient("mongodb://localhost:27017/")

chat_store = MongoChatStore(
    client=client,
    amongo_client=async_client,
    db_name="llama_index",
    collection_name="chat_sessions",
)

You can also initialize the chat store with a Collection or AsyncCollection.

from pymongo import Collection
from pymongo.asynchronous import AsyncCollection

client = MongoClient("mongodb://localhost:27017/")
async_client = AsyncMongoClient("mongodb://localhost:27017/")

collection = client["llama_index"]["chat_sessions"]
async_collection = async_client["llama_index"]["chat_sessions"]

chat_store = MongoChatStore(
    collection=collection, async_collection=async_collection
)

Usage with LlamaIndex

from llama_index.core.chat_engine.types import ChatMessage

chat_memory = ChatMemoryBuffer.from_defaults(
    token_limit=3000,
    chat_store=chat_store,
    chat_store_key="user1",
)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llama_index_storage_chat_store_mongo-0.5.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file llama_index_storage_chat_store_mongo-0.5.0.tar.gz.

File metadata

  • Download URL: llama_index_storage_chat_store_mongo-0.5.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llama_index_storage_chat_store_mongo-0.5.0.tar.gz
Algorithm Hash digest
SHA256 fd92359f6e2510af770411911c1f2a899963204dbbc6db49fcc4a4be75d84e98
MD5 d782420275c17506ca41458dd22c2a66
BLAKE2b-256 4500288faa500a6c28f7df7120dd29c2fda87c5912d7aa046586a42d92906aea

See more details on using hashes here.

File details

Details for the file llama_index_storage_chat_store_mongo-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: llama_index_storage_chat_store_mongo-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llama_index_storage_chat_store_mongo-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3a8460f7df6f5bbcb85441b2a861b43a8aa3a86f4c2dee9c7d67f507e8e6077c
MD5 96e55051a9006b4a17e148a1fe53f8dc
BLAKE2b-256 95715ad4ebdac50cb5b26e47f1f684b0dad7f83c273449ac7c7baa90ac299e78

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 files

0.4.0

2 files

0.3.0

2 files

0.2.1

2 files

0.2.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page