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

llama_index_storage_chat_store_mongo-0.2.0.tar.gz (5.3 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.2.0.tar.gz.

File metadata

File hashes

Hashes for llama_index_storage_chat_store_mongo-0.2.0.tar.gz
Algorithm Hash digest
SHA256 510ddd30ae335a849836bf047f974796c306a6f7599c14b236c55aa127080876
MD5 0a1df17c2d0f2d7f4176b24b18000e3d
BLAKE2b-256 a6cd4a7d4ab6d5d6163069fdc4f9007ecc125c322a65d5fd9db7b931b74b0b0e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llama_index_storage_chat_store_mongo-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 532031f384948f5f05ba77d78740188a228ab5fe2a167038b7a318f931960384
MD5 c70f6743f6cd4cf08a8fb0554de6dea7
BLAKE2b-256 4b752ed62d3b77df19ea564b502bb440997a0be98590e3accb7bf8f51f2a76d5

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