Skip to main content

llama-index storage-chat-store mongo integration

Project description

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 AsyncIOMotorClient and a database name and collection name.

from pymongo import MongoClient
from motor.motor_asyncio import AsyncIOMotorClient

client = MongoClient("mongodb://localhost:27017/")
async_client = AsyncIOMotorClient("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 AsyncIOMotorCollection.

from pymongo import Collection
from motor.motor_asyncio import AsyncIOMotorCollection

client = MongoClient("mongodb://localhost:27017/")
async_client = AsyncIOMotorClient("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",
)

Project details


Download files

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

Source Distribution

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.2.1.tar.gz.

File metadata

File hashes

Hashes for llama_index_storage_chat_store_mongo-0.2.1.tar.gz
Algorithm Hash digest
SHA256 44e845fa3293d8e8d3c0c0204830be947134e089a4e342f2181153aae627bc8c
MD5 3398352da44e2e11fcf015c4028dd251
BLAKE2b-256 33d8e61e612470875aeaa70c43829fa0ace546aea8a8d83260484e8b310c293b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llama_index_storage_chat_store_mongo-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b758700fa7b35c9e9f5ee8912fa5cd7a8ea347a3f31871a4cc8a8f67cd6933bc
MD5 07dd8d4cf9e2a6cfd054c65deb00dcf9
BLAKE2b-256 deb40f67685d53a9cd796af4c708300d1256b9ef6097d895bdb7f98bf1baa2d6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page