Skip to content

Commit 79c9f2a

Browse files
authored
feat: add OpenSearch chat store integration (#20796)
* feat: add OpenSearch chat store integration Add a new llama-index-storage-chat-store-opensearch package that implements BaseChatStore backed by OpenSearch. Stores chat messages as individual documents keyed by session_id with integer indices for ordering. Includes full sync and async support. Closes #15926 * refactor: remove guarded imports, opensearch-py is a direct dependency * docs: expand README with installation and usage examples
1 parent f6b8a6d commit 79c9f2a

File tree

8 files changed

+6639
-0
lines changed

8 files changed

+6639
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
GIT_ROOT ?= $(shell git rev-parse --show-toplevel)
2+
3+
help: ## Show all Makefile targets.
4+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[33m%-30s\033[0m %s\n", $$1, $$2}'
5+
6+
format: ## Run code autoformatters (black).
7+
pre-commit install
8+
git ls-files | xargs pre-commit run black --files
9+
10+
lint: ## Run linters: pre-commit (black, ruff, codespell) and mypy
11+
pre-commit install && git ls-files | xargs pre-commit run --show-diff-on-failure --files
12+
13+
test: ## Run tests via pytest.
14+
pytest tests
15+
16+
watch-docs: ## Build and watch documentation.
17+
sphinx-autobuild docs/ docs/_build/html --open-browser --watch $(GIT_ROOT)/llama_index/
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# LlamaIndex Chat Store Integration: OpenSearch
2+
3+
## Installation
4+
5+
```
6+
pip install llama-index-storage-chat-store-opensearch
7+
```
8+
9+
## Usage
10+
11+
Using `OpensearchChatStore`, you can store your chat history in OpenSearch, without having to worry about manually persisting and loading the chat history.
12+
13+
```python
14+
from llama_index.storage.chat_store.opensearch import OpensearchChatStore
15+
from llama_index.core.memory import ChatMemoryBuffer
16+
17+
chat_store = OpensearchChatStore(
18+
opensearch_url="https://localhost:9200",
19+
)
20+
21+
chat_memory = ChatMemoryBuffer.from_defaults(
22+
token_limit=3000,
23+
chat_store=chat_store,
24+
chat_store_key="user1",
25+
)
26+
```
27+
28+
### Custom Index Name
29+
30+
```python
31+
chat_store = OpensearchChatStore(
32+
opensearch_url="https://localhost:9200",
33+
index="my_chat_store",
34+
)
35+
```
36+
37+
### Using a Pre-configured Client
38+
39+
```python
40+
from opensearchpy import OpenSearch
41+
42+
client = OpenSearch(
43+
"https://localhost:9200",
44+
http_auth=("admin", "admin"),
45+
verify_certs=False,
46+
)
47+
48+
chat_store = OpensearchChatStore(
49+
opensearch_url="https://localhost:9200",
50+
os_client=client,
51+
)
52+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from llama_index.storage.chat_store.opensearch.base import OpensearchChatStore
2+
3+
__all__ = ["OpensearchChatStore"]

0 commit comments

Comments
 (0)