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 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",
)

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.3.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.3.0.tar.gz.

File metadata

File hashes

Hashes for llama_index_storage_chat_store_mongo-0.3.0.tar.gz
Algorithm Hash digest
SHA256 a317e34b24cafc5d4b126c14215e76a59ac098e9b7b00488b6ae2e68d816340c
MD5 b0c9100c7ba54f21f35efee05046f12b
BLAKE2b-256 beefe30beeb723b7d069513581a75dd85918adbd016c5ac375322431a8750b96

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llama_index_storage_chat_store_mongo-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5f2c9a2ecbbf2d68106b9f1680d191e6f5266dcda22b2ff9ae1a3cdd33fdeef2
MD5 3b459673cd94cc198d97bfad8fcba374
BLAKE2b-256 5e63eb9790689dc531e643e5382ba2d40bd8781422500a5d90f754343389d498

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