Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArangoDB Integration #3

Draft
wants to merge 24 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
20e906a
arangodb prep | initial commit
aMahanna Oct 23, 2024
388d802
ArangoDB: Feedback management (#11)
ajaykallepalli Nov 25, 2024
6973d91
remove: `PROTOCOL` env
aMahanna Nov 26, 2024
5e9742c
ArangoDB: PromptRegistry (#8)
SLasyaN Nov 26, 2024
0e9ed3b
arangodb prep | initial commit
aMahanna Oct 23, 2024
7bd5aaa
ArangoDB: Feedback management (#11)
ajaykallepalli Nov 25, 2024
b6ded9f
remove: `PROTOCOL` env
aMahanna Nov 26, 2024
1746749
ArangoDB: PromptRegistry (#8)
SLasyaN Nov 26, 2024
bf41327
ArangoDB: Chathistory (#10)
ajaykallepalli Nov 26, 2024
9d46b27
update ChatHistory README
aMahanna Nov 26, 2024
029c1fd
new: tests
aMahanna Nov 26, 2024
3a80607
update: docker compose workflows
aMahanna Nov 26, 2024
28a5030
Merge branch 'arangodb' of https://github.com/arangoml/GenAIComps int…
ajaykallepalli Nov 27, 2024
fabd85c
fix: `arango`
aMahanna Nov 27, 2024
0c21ff5
fix: python path
aMahanna Nov 27, 2024
c5b936b
rename arango envs (#14)
aMahanna Dec 9, 2024
23ac66a
ArangoDB: Dataprep (#12)
aMahanna Dec 30, 2024
3244533
new: `source_metadata_fields_to_extract_to_top_level`
aMahanna Dec 30, 2024
3604fb8
fix: logger info
aMahanna Dec 30, 2024
50b2639
ArangoDB: Retriever (#2)
aMahanna Jan 5, 2025
9a7d810
revert: feedback management mongo change
aMahanna Jan 5, 2025
86aca77
Merge branch 'arangodb' of https://github.com/arangoml/GenAIComps int…
aMahanna Jan 5, 2025
f0659ad
add logs
aMahanna Jan 6, 2025
aa26013
dataprep improvements (#16)
aMahanna Jan 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/docker/compose/chathistory-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ services:
build:
dockerfile: comps/chathistory/mongo/Dockerfile
image: ${REGISTRY:-opea}/chathistory-mongo-server:${TAG:-latest}
chathistory-arango-server:
build:
dockerfile: comps/chathistory/arango/Dockerfile
image: ${REGISTRY:-opea}/chathistory-arango-server:${TAG:-latest}
4 changes: 4 additions & 0 deletions .github/workflows/docker/compose/dataprep-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@ services:
build:
dockerfile: comps/dataprep/multimedia2text/audio2text/Dockerfile
image: ${REGISTRY:-opea}/dataprep-audio2text:${TAG:-latest}
dataprep-arango:
build:
dockerfile: comps/dataprep/arango/langchain/Dockerfile
image: ${REGISTRY:-opea}/dataprep-arango:${TAG:-latest}
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ services:
build:
dockerfile: comps/feedback_management/mongo/Dockerfile
image: ${REGISTRY:-opea}/feedbackmanagement:${TAG:-latest}
feedbackmanagement-arango-server:
build:
dockerfile: comps/feedback_management/arango/Dockerfile
image: ${REGISTRY:-opea}/feedbackmanagement-arango-server:${TAG:-latest}
4 changes: 4 additions & 0 deletions .github/workflows/docker/compose/prompt_registry-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ services:
build:
dockerfile: comps/prompt_registry/mongo/Dockerfile
image: ${REGISTRY:-opea}/promptregistry-mongo-server:${TAG:-latest}
promptregistry-arango-server:
build:
dockerfile: comps/prompt_registry/arango/Dockerfile
image: ${REGISTRY:-opea}/promptregistry-arango-server:${TAG:-latest}
4 changes: 4 additions & 0 deletions .github/workflows/docker/compose/retrievers-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@ services:
build:
dockerfile: comps/retrievers/neo4j/llama_index/Dockerfile
image: ${REGISTRY:-opea}/retriever-neo4j-llamaindex:${TAG:-latest}
retriever-arango:
build:
dockerfile: comps/retrievers/arango/langchain/Dockerfile
image: ${REGISTRY:-opea}/retriever-arango:${TAG:-latest}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
__pycache__
*.egg-info/
.DS_Store
.venv
33 changes: 33 additions & 0 deletions ARANGODB_README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Instructions

0. Create a virtual environment:

```bash
python -m venv .venv

source .venv/bin/activate
```

1. Install the required packages:

```bash
pip install python-arango
pip install langchain_openai
pip install git+https://github.com/arangoml/langchain.git@arangodb#subdirectory=libs/community
```

2. Provision the ArangoDB with Vector Index image:

```bash
docker create --name arango-vector -p 8529:8529 -e ARANGO_ROOT_PASSWORD=test jbajic/arangodb-arm:vector-index-preview

docker start arango-vector
```

3. Set your `OPENAI_API_KEY` environment variable (contact Anthony for access)

4. Run the test script to confirm LangChain is working:

```bash
python langchain_test.py
```
4 changes: 4 additions & 0 deletions comps/chathistory/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ The Chat History microservice able to support various database backends for stor
### Chat History with MongoDB

For more detail, please refer to this [README](./mongo/README.md)

### Chat History with ArangoDB

For more detail, please refer to this [README](./arango/README.md)
30 changes: 30 additions & 0 deletions comps/chathistory/arango/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

FROM python:3.11-slim

ENV LANG=C.UTF-8

RUN apt-get update -y && apt-get install -y --no-install-recommends --fix-missing \
build-essential \
libjemalloc-dev \
libgl1-mesa-glx

RUN useradd -m -s /bin/bash user && \
mkdir -p /home/user && \
chown -R user /home/user/

USER user

COPY comps /home/user/comps
COPY requirements.txt /home/user/

RUN pip install --no-cache-dir --upgrade pip setuptools && \
pip install --no-cache-dir -r /home/user/comps/chathistory/arango/requirements.txt && \
pip install --no-cache-dir -r /home/user/requirements.txt

ENV PYTHONPATH=$PYTHONPATH:/home/user

WORKDIR /home/user/comps/chathistory/arango

ENTRYPOINT ["python", "chat.py"]
119 changes: 119 additions & 0 deletions comps/chathistory/arango/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# 📝 Chat History Microservice with ArangoDB

This README provides setup guides and all the necessary information about the Chat History microservice with ArangoDB database.

---

## Setup Environment Variables

See `config.py` for default values.

```bash
export ARANGO_URL=${ARANGO_URL}
export ARANGO_USERNAME=${ARANGO_USERNAME}
export ARANGO_PASSWORD=${ARANGO_PASSWORD}
export ARANGO_DB_NAME=${ARANGO_DB_NAME}
export ARANGO_COLLECTION_NAME=${ARANGO_COLLECTION_NAME}
```

---

## 🚀Start Microservice with Docker

### Build Docker Image

```bash
cd ../../../../
docker build -t opea/chathistory-arango-server:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/chathistory/arango/Dockerfile .
```

### Run Docker with CLI

- Run ArangoDB image container

```bash
docker run -d -p 8529:8529 --name=arango arangodb/arangodb:latest
```

- Run the Chat History microservice

```bash
docker run -p 6012:6012 \
-e http_proxy=$http_proxy \
-e https_proxy=$https_proxy \
-e no_proxy=$no_proxy \
-e ARANGO_URL=${ARANGO_URL} \
-e ARANGO_USERNAME=${ARANGO_USERNAME} \
-e ARANGO_PASSWORD=${ARANGO_PASSWORD} \
-e ARANGO_DB_NAME=${ARANGO_DB_NAME} \
-e ARANGO_COLLECTION_NAME=${ARANGO_COLLECTION_NAME} \
opea/chathistory-arango-server:latest
```

---

## ✅ Invoke Microservice

The Chat History microservice exposes the following API endpoints:

- Create new chat conversation

```bash
curl -X 'POST' \
http://${host_ip}:6012/v1/chathistory/create \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"data": {
"messages": "test Messages", "user": "test"
}
}'
```

- Get all the Conversations for a user

```bash
curl -X 'POST' \
http://${host_ip}:6012/v1/chathistory/get \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"user": "test"}'
```

- Get a specific conversation by id.

```bash
curl -X 'POST' \
http://${host_ip}:6012/v1/chathistory/get \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"user": "test", "id":"48918"}'
```

- Update the conversation by id.

```bash
curl -X 'POST' \
http://${host_ip}:6012/v1/chathistory/create \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"data": {
"messages": "test Messages Update", "user": "test"
},
"id":"48918"
}'
```

- Delete a stored conversation.

```bash
curl -X 'POST' \
http://${host_ip}:6012/v1/chathistory/delete \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"user": "test", "id":"48918"}'
```
32 changes: 32 additions & 0 deletions comps/chathistory/arango/arango_conn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

from arango import ArangoClient as PythonArangoClient
from arango.database import StandardDatabase
from config import ARANGO_URL, ARANGO_PASSWORD, ARANGO_USERNAME, ARANGO_DB_NAME


class ArangoClient:
conn_url = ARANGO_URL

@staticmethod
def get_db_client() -> StandardDatabase:
try:
# Create client
client = PythonArangoClient(hosts=ArangoClient.conn_url)

# First connect to _system database
sys_db = client.db("_system", username=ARANGO_USERNAME, password=ARANGO_PASSWORD, verify=True)

# Create target database if it doesn't exist
if not sys_db.has_database(ARANGO_DB_NAME):
sys_db.create_database(ARANGO_DB_NAME)

# Now connect to the target database
db = client.db(ARANGO_DB_NAME, username=ARANGO_USERNAME, password=ARANGO_PASSWORD, verify=True)

return db

except Exception as e:
print(e)
raise e
Loading
Loading