-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support llamaindex for retrieval microservice and remove langchain de…
…pendency for llm and rerank microservice (#152) * remove langchain dependency for llm and rerank Signed-off-by: lvliang-intel <[email protected]> * add llamaindex support for retrieval Signed-off-by: lvliang-intel <[email protected]> * fix schema issue Signed-off-by: lvliang-intel <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix dockerfile Signed-off-by: lvliang-intel <[email protected]> * update readme Signed-off-by: lvliang-intel <[email protected]> * update reamde Signed-off-by: lvliang-intel <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix entrypoint Signed-off-by: lvliang-intel <[email protected]> * add dataprep process in test script Signed-off-by: lvliang-intel <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix redis url for dataprep Signed-off-by: lvliang-intel <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * update readme Signed-off-by: lvliang-intel <[email protected]> * update code Signed-off-by: lvliang-intel <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: lvliang-intel <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: root <[email protected]>
- Loading branch information
1 parent
9b658f4
commit 61795fd
Showing
18 changed files
with
356 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
docarray[full] | ||
fastapi | ||
langchain | ||
langsmith | ||
opentelemetry-api | ||
opentelemetry-exporter-otlp | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# Retriever Microservice | ||
|
||
This retriever microservice is a highly efficient search service designed for handling and retrieving embedding vectors. It operates by receiving an embedding vector as input and conducting a similarity search against vectors stored in a VectorDB database. Users must specify the VectorDB's URL and the index name, and the service searches within that index to find documents with the highest similarity to the input vector. | ||
|
||
The service primarily utilizes similarity measures in vector space to rapidly retrieve contentually similar documents. The vector-based retrieval approach is particularly suited for handling large datasets, offering fast and accurate search results that significantly enhance the efficiency and quality of information retrieval. | ||
|
||
Overall, this microservice provides robust backend support for applications requiring efficient similarity searches, playing a vital role in scenarios such as recommendation systems, information retrieval, or any other context where precise measurement of document similarity is crucial. | ||
|
||
# 🚀1. Start Microservice with Python (Option 1) | ||
|
||
To start the retriever microservice, you must first install the required python packages. | ||
|
||
## 1.1 Install Requirements | ||
|
||
```bash | ||
pip install -r requirements.txt | ||
``` | ||
|
||
## 1.2 Setup VectorDB Service | ||
|
||
You need to setup your own VectorDB service (Redis in this example), and ingest your knowledge documents into the vector database. | ||
|
||
As for Redis, you could start a docker container using the following commands. | ||
Remember to ingest data into it manually. | ||
|
||
```bash | ||
docker run -d --name="redis-vector-db" -p 6379:6379 -p 8001:8001 redis/redis-stack:7.2.0-v9 | ||
``` | ||
|
||
And then ingest data into the Redis VectorDB using the methods described in the dataprep microservice. | ||
|
||
## 1.3 Start Retriever Service | ||
|
||
```bash | ||
python retriever_redis.py | ||
``` | ||
|
||
# 🚀2. Start Microservice with Docker (Option 2) | ||
|
||
## 2.1 Setup Environment Variables | ||
|
||
```bash | ||
export REDIS_URL="redis://${your_ip}:6379" | ||
export INDEX_NAME=${your_index_name} | ||
export LANGCHAIN_TRACING_V2=true | ||
export LANGCHAIN_API_KEY=${your_langchain_api_key} | ||
export LANGCHAIN_PROJECT="opea/retrievers" | ||
``` | ||
|
||
## 2.2 Build Docker Image | ||
|
||
```bash | ||
cd ../../ | ||
docker build -t opea/retriever-redis-llamaindex:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/retrievers/llamaindex/docker/Dockerfile . | ||
``` | ||
|
||
To start a docker container, you have two options: | ||
|
||
- A. Run Docker with CLI | ||
- B. Run Docker with Docker Compose | ||
|
||
You can choose one as needed. | ||
|
||
## 2.3 Run Docker with CLI (Option A) | ||
|
||
```bash | ||
docker run -d --name="retriever-redis-server" -p 7000:7000 --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e REDIS_URL=$REDIS_URL -e INDEX_NAME=$INDEX_NAME opea/retriever-redis:latest | ||
``` | ||
|
||
## 2.4 Run Docker with Docker Compose (Option B) | ||
|
||
```bash | ||
cd llamaindex/docker | ||
docker compose -f docker_compose_retriever.yaml up -d | ||
``` | ||
|
||
# 🚀3. Consume Retriever Service | ||
|
||
## 3.1 Check Service Status | ||
|
||
```bash | ||
curl http://localhost:7000/v1/health_check \ | ||
-X GET \ | ||
-H 'Content-Type: application/json' | ||
``` | ||
|
||
## 3.2 Consume Retriever Service | ||
|
||
To consume the Retriever Microservice, you can generate a mock embedding vector of length 768 with Python. | ||
|
||
```bash | ||
your_embedding=$(python -c "import random; embedding = [random.uniform(-1, 1) for _ in range(768)]; print(embedding)") | ||
curl http://${your_ip}:7000/v1/retrieval \ | ||
-X POST \ | ||
-d "{\"text\":\"What is the revenue of Nike in 2023?\",\"embedding\":${your_embedding}}" \ | ||
-H 'Content-Type: application/json' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
FROM ubuntu:22.04 | ||
|
||
RUN apt-get update -y && apt-get install -y --no-install-recommends --fix-missing \ | ||
libgl1-mesa-glx \ | ||
libjemalloc-dev \ | ||
vim | ||
|
||
RUN useradd -m -s /bin/bash user && \ | ||
mkdir -p /home/user && \ | ||
chown -R user /home/user/ | ||
|
||
COPY comps /home/user/comps | ||
|
||
USER user | ||
|
||
RUN pip install --no-cache-dir --upgrade pip && \ | ||
pip install --no-cache-dir -r /home/user/comps/retrievers/llamaindex/requirements.txt | ||
|
||
ENV PYTHONPATH=$PYTHONPATH:/home/user | ||
|
||
WORKDIR /home/user/comps/retrievers/llamaindex | ||
|
||
ENTRYPOINT ["python", "retriever_redis.py"] |
29 changes: 29 additions & 0 deletions
29
comps/retrievers/llamaindex/docker/docker_compose_retriever.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
version: "3.8" | ||
|
||
services: | ||
redis-vector-db: | ||
image: redis/redis-stack:7.2.0-v9 | ||
container_name: redis-vector-db | ||
ports: | ||
- "6379:6379" | ||
- "8001:8001" | ||
retriever: | ||
image: opea/retriever-redis:latest | ||
container_name: retriever-redis-server | ||
ports: | ||
- "7000:7000" | ||
ipc: host | ||
environment: | ||
http_proxy: ${http_proxy} | ||
https_proxy: ${https_proxy} | ||
REDIS_URL: ${REDIS_URL} | ||
INDEX_NAME: ${INDEX_NAME} | ||
LANGCHAIN_API_KEY: ${LANGCHAIN_API_KEY} | ||
restart: unless-stopped | ||
|
||
networks: | ||
default: | ||
driver: bridge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import os | ||
|
||
|
||
def get_boolean_env_var(var_name, default_value=False): | ||
"""Retrieve the boolean value of an environment variable. | ||
Args: | ||
var_name (str): The name of the environment variable to retrieve. | ||
default_value (bool): The default value to return if the variable | ||
is not found. | ||
Returns: | ||
bool: The value of the environment variable, interpreted as a boolean. | ||
""" | ||
true_values = {"true", "1", "t", "y", "yes"} | ||
false_values = {"false", "0", "f", "n", "no"} | ||
|
||
# Retrieve the environment variable's value | ||
value = os.getenv(var_name, "").lower() | ||
|
||
# Decide the boolean value based on the content of the string | ||
if value in true_values: | ||
return True | ||
elif value in false_values: | ||
return False | ||
else: | ||
return default_value | ||
|
||
|
||
# Whether or not to enable langchain debugging | ||
DEBUG = get_boolean_env_var("DEBUG", False) | ||
# Set DEBUG env var to "true" if you wish to enable LC debugging module | ||
if DEBUG: | ||
import langchain | ||
|
||
langchain.debug = True | ||
|
||
|
||
# Embedding model | ||
EMBED_MODEL = os.getenv("EMBED_MODEL", "BAAI/bge-base-en-v1.5") | ||
|
||
|
||
# Redis Connection Information | ||
REDIS_HOST = os.getenv("REDIS_HOST", "localhost") | ||
REDIS_PORT = int(os.getenv("REDIS_PORT", 6379)) | ||
|
||
|
||
def format_redis_conn_from_env(): | ||
redis_url = os.getenv("REDIS_URL", None) | ||
if redis_url: | ||
return redis_url | ||
else: | ||
using_ssl = get_boolean_env_var("REDIS_SSL", False) | ||
start = "rediss://" if using_ssl else "redis://" | ||
|
||
# if using RBAC | ||
password = os.getenv("REDIS_PASSWORD", None) | ||
username = os.getenv("REDIS_USERNAME", "default") | ||
if password is not None: | ||
start += f"{username}:{password}@" | ||
|
||
return start + f"{REDIS_HOST}:{REDIS_PORT}" | ||
|
||
|
||
REDIS_URL = format_redis_conn_from_env() | ||
|
||
# Vector Index Configuration | ||
INDEX_NAME = os.getenv("INDEX_NAME", "rag-redis") | ||
|
||
|
||
current_file_path = os.path.abspath(__file__) | ||
parent_dir = os.path.dirname(current_file_path) | ||
REDIS_SCHEMA = os.getenv("REDIS_SCHEMA", "redis_schema.yml") | ||
INDEX_SCHEMA = os.path.join(parent_dir, REDIS_SCHEMA) |
Oops, something went wrong.