Metadata-Version: 2.4
Name: llama-index-storage-chat-store-mongo
Version: 0.4.0
Summary: llama-index storage-chat-store mongo integration
Author-email: Vrushab Ghodke <vrushab.ghodke@gmail.com>
License-Expression: MIT
License-File: LICENSE
Requires-Python: <4.0,>=3.10
Requires-Dist: llama-index-core<0.15,>=0.13.0
Requires-Dist: pymongo<5,>=4.13.0
Description-Content-Type: text/markdown

# LlamaIndex Chat Store Integration: MongoDB Chat Store

## Installation

```bash
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.

```python
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.

```python
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`.

```python
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

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