Metadata-Version: 2.4
Name: oliviadb-llamaindex
Version: 0.1.2
Summary: LlamaIndex Memory backed by OliviaDB: a chat store and a long-term memory block
License-Expression: Apache-2.0
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: oliviadb>=0.1.0
Requires-Dist: llama-index-core<0.15,>=0.14.20

<!-- SPDX-License-Identifier: Apache-2.0 -->
# oliviadb-llamaindex

[LlamaIndex](https://www.llamaindex.ai/) memory in [OliviaDB](https://olivia-db.com/): a chat
store (`OliviaDBChatStore`, active and archived chat history) and a memory block
(`OliviaDBMemoryBlock`: flushed messages remembered, recalled for the latest message). Tested
with llama-index-core 0.14.26.

## Install

```sh
pip install oliviadb-llamaindex
```

Python 3.10 or later.

## Example

A server from the core image (`docker run -d -p 8443:8443 -v oliviadb-data:/data
ghcr.io/oliviadb/oliviadb`), its API key in `OLIVIADB_API_KEY` and its certificate in
`oliviadb-ca.pem` (`docker cp <container>:/data/tls/server.pem oliviadb-ca.pem`):

```python
import asyncio
import os

from llama_index.core.base.llms.types import ChatMessage
from llama_index.core.memory import Memory
from oliviadb import OliviaDbClient
from oliviadb_llamaindex import OliviaDBChatStore, OliviaDBMemoryBlock

client = OliviaDbClient("https://localhost:8443", api_key=os.environ["OLIVIADB_API_KEY"], ca_file="oliviadb-ca.pem")


async def main():
    memory = Memory.from_defaults(
        session_id="user-1",
        chat_store=OliviaDBChatStore(client, root=("llamaindex", "assistant")),
        memory_blocks=[OliviaDBMemoryBlock(client=client, thread="assistant")],
    )
    await memory.aput(ChatMessage(role="user", content="I play the cello on Sundays."))
    print(await memory.aget())


asyncio.run(main())
```

## Links

* Documentation: <https://docs.olivia-db.com/>
* Repository: <https://github.com/OliviaDB/oliviadb-python> (`adapters/llamaindex`)

Licence: Apache-2.0.
