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

File metadata

File hashes

Hashes for llama_index_storage_chat_store_mongo-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0d844f3cc7b732627db3007b50830dea37eb012e472654b53490c107b873b336
MD5 5a22ecb98f2eb1351edb00f2b0b1efda
BLAKE2b-256 55b5764880533d3a1cc234d819598213587287599cfe16f181d5b870a4b149f7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llama_index_storage_chat_store_mongo-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a522a021704eb733609d59ea25b3b906dadfe289f8b76b812655b386635957fc
MD5 11d516d2ed14e5405fd8a0ae8118b078
BLAKE2b-256 59e6ef40a2fb17c10c0dccc46115b9661da86e43f0d6f585ac878bae679dd415

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