Skip to content

Commit fc7c3a7

Browse files
committed
sync with ec-rag 25.09
Signed-off-by: Yongbozzz <yongbo.zhu@intel.com>
1 parent 385b2d5 commit fc7c3a7

51 files changed

Lines changed: 1155 additions & 730 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

EdgeCraftRAG/Dockerfile.server

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,38 @@
11
FROM python:3.11-slim
22

33
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
4-
5-
RUN apt-get update -y && apt-get install -y --no-install-recommends --fix-missing \
6-
libjemalloc-dev \
7-
libmagic1 \
8-
libglib2.0-0 \
9-
poppler-utils \
10-
tesseract-ocr
11-
12-
RUN apt-get update && apt-get install -y gnupg wget git
13-
RUN wget -qO - https://repositories.intel.com/gpu/intel-graphics.key | \
14-
gpg --yes --dearmor --output /usr/share/keyrings/intel-graphics.gpg
15-
RUN echo "deb [arch=amd64,i386 signed-by=/usr/share/keyrings/intel-graphics.gpg] https://repositories.intel.com/gpu/ubuntu jammy client" | \
16-
tee /etc/apt/sources.list.d/intel-gpu-jammy.list
17-
RUN apt-get update && apt-get install -y \
18-
intel-opencl-icd intel-level-zero-gpu \
19-
intel-level-zero-gpu-raytracing \
20-
intel-media-va-driver-non-free libmfx1 libmfxgen1 libvpl2 \
21-
libegl-mesa0 libegl1-mesa libegl1-mesa-dev libgbm1 libgl1-mesa-dev libgl1-mesa-dri \
22-
libglapi-mesa libgles2-mesa-dev libglx-mesa0 libigdgmm12 libxatracker2 mesa-va-drivers \
23-
mesa-vdpau-drivers mesa-vulkan-drivers va-driver-all vainfo hwinfo clinfo
4+
RUN apt-get update && apt-get install -y gnupg2 wget git
5+
RUN apt-get remove -y libze-intel-gpu1 libigc1 libigdfcl1 libze-dev || true; \
6+
   apt-get update; \
7+
   apt-get install -y curl
8+
RUN curl -sL 'https://keyserver.ubuntu.com/pks/lookup?fingerprint=on&op=get&search=0x0C0E6AF955CE463C03FC51574D098D70AFBE5E1F' | tee /etc/apt/trusted.gpg.d/driver.asc
9+
RUN echo -e "Types: deb\nURIs: https://ppa.launchpadcontent.net/kobuk-team/intel-graphics/ubuntu/\nSuites: plucky\nComponents: main\nSigned-By: /etc/apt/trusted.gpg.d/driver.asc" > /etc/apt/sources.list.d/driver.sources
10+
RUN apt update && apt-get install -y libze-intel-gpu1 libze1 intel-metrics-discovery intel-opencl-icd clinfo intel-gsc && apt-get install -y libze-intel-gpu1 libze1 intel-metrics-discovery intel-opencl-icd clinfo intel-gsc && apt-get install -y libze-dev intel-ocloc libze-intel-gpu-raytracing
2411

2512
RUN useradd -m -s /bin/bash user && \
26-
mkdir -p /home/user && \
27-
chown -R user /home/user/
13+
   mkdir -p /home/user && \
14+
   chown -R user /home/user/
2815

2916
RUN mkdir /templates && \
30-
chown -R user /templates
17+
   chown -R user /templates
3118
COPY ./edgecraftrag/prompt_template/default_prompt.txt /templates/
3219
RUN chown -R user /templates/default_prompt.txt
3320

3421
COPY ./edgecraftrag /home/user/edgecraftrag
3522

36-
RUN mkdir -p /home/user/ui_cache
23+
RUN mkdir -p /home/user/ui_cache
3724
ENV UI_UPLOAD_PATH=/home/user/ui_cache
3825

3926
USER user
4027

4128
WORKDIR /home/user/edgecraftrag
42-
RUN pip install --no-cache-dir --upgrade pip setuptools==70.0.0 && \
43-
pip install --no-cache-dir --extra-index-url https://download.pytorch.org/whl/cpu -r requirements.txt
29+
RUN pip3 install --no-cache-dir --upgrade setuptools==70.0.0 --break-system-packages && \
30+
   pip3 install --no-cache-dir --extra-index-url https://download.pytorch.org/whl/cpu -r requirements.txt --break-system-packages
31+
32+
RUN pip3 install --no-cache-dir docarray==0.40.0 --break-system-packages
4433

4534
WORKDIR /home/user/
4635
RUN git clone https://github.com/openvinotoolkit/openvino.genai.git genai
4736
ENV PYTHONPATH="$PYTHONPATH:/home/user/genai/tools/llm_bench"
4837

49-
ENTRYPOINT ["python", "-m", "edgecraftrag.server"]
38+
ENTRYPOINT ["python3", "-m", "edgecraftrag.server"]

EdgeCraftRAG/docker_compose/intel/gpu/arc/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ For more advanced env variables and configurations, please refer to [Prepare env
9595

9696
### 5. Deploy the Service on Intel GPU Using Docker Compose
9797

98-
set Milvus DB and chat history round for inference:
99-
98+
set Milvus DB and chat history round for inference:
10099
```bash
101100
# EC-RAG support Milvus as persistent database, by default milvus is disabled, you can choose to set MILVUS_ENABLED=1 to enable it
102101
export MILVUS_ENABLED=0
@@ -124,7 +123,7 @@ docker compose -f docker_compose/intel/gpu/arc/compose_vllm.yaml up -d
124123
#### option b. Deploy the Service on Arc B60 Using Docker Compose
125124

126125
```bash
127-
# Besides MILVUS_ENABLED and CHAT_HISTORY_ROUND, below environments are exposed for vLLM config, you can change them to your preference:
126+
# Besides MILVUS_ENABLED and CHAT_HISTORY_ROUND, below enviroments are exposed for vLLM config, you can change them to your preference:
128127
# export VLLM_SERVICE_PORT_B60=8086
129128
# export DTYPE=float16
130129
# export TP=1 # for multi GPU, you can change TP value

EdgeCraftRAG/docker_compose/intel/gpu/arc/compose_vllm_b60.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,4 @@ services:
183183
-dp=$${DP}"
184184
networks:
185185
default:
186-
driver: bridge
186+
driver: bridge

EdgeCraftRAG/docs/API_Guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,4 @@ curl -X POST http://${HOST_IP}:16010/v1/retrieval -H "Content-Type: application/
219219

220220
```bash
221221
curl -X POST http://${HOST_IP}:16011/v1/chatqna -H "Content-Type: application/json" -d '{"messages":"#REPLACE WITH YOUR QUESTION HERE#", "top_n":5, "max_tokens":512}' | jq '.'
222-
```
222+
```

EdgeCraftRAG/docs/Advanced_Setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,6 @@ Model preparation is the same as vLLM inference section, please refer to [Prepar
208208

209209
This section is the same as default vLLM inference section, please refer to [Prepare env variables and configurations](../docker_compose/intel/gpu/arc/README.md#prepare-env-variables-and-configurations) and [Start Edge Craft RAG Services with Docker Compose](../docker_compose/intel/gpu/arc/README.md#deploy-the-service-on-arc-a770-using-docker-compose)
210210

211-
### 2. Access Kbadmin UI
211+
### 2. Access Kbadmin UI
212212

213213
please refer to [ChatQnA with Kbadmin in UI](./Explore_Edge_Craft_RAG.md#chatqna-with-kbadmin-in-ui)

EdgeCraftRAG/docs/Explore_Edge_Craft_RAG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ After knowledge base creation, you can upload the documents for retrieval.
3434
Then, you can submit messages in the chat box in `Chat` page.
3535
![chat_with_rag](../assets/img/chatqna.png)
3636

37-
## ChatQnA with Kbadmin in UI
37+
## ChatQnA with Kbadmin in UI
3838

3939
### Kbadmin Pipeline
4040

@@ -52,4 +52,4 @@ Please select 'kbadmin' in `Type`and select kb name from the kbs you created in
5252
![upload_data](../assets/img/kbadmin_kb.png)
5353

5454
Then, you can submit messages in the chat box in `Chat` page.
55-
![chat_with_rag](../assets/img/chatqna.png)
55+
![chat_with_rag](../assets/img/chatqna.png)

EdgeCraftRAG/edgecraftrag/api/v1/chatqna.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async def chatqna(request: ChatCompletionRequest):
3838
active_kb = ctx.knowledgemgr.get_active_knowledge_base()
3939
request.user = active_kb if active_kb else None
4040
if experience_kb:
41-
request.tool_choice = "auto" if experience_kb.experience_active else "none"
41+
request.tool_choice = 'auto' if experience_kb.experience_active else 'none'
4242
generator = ctx.get_pipeline_mgr().get_active_pipeline().generator
4343
if generator:
4444
request.model = generator.model_id
@@ -62,7 +62,7 @@ async def ragqna(request: ChatCompletionRequest):
6262
active_kb = ctx.knowledgemgr.get_active_knowledge_base()
6363
request.user = active_kb if active_kb else None
6464
if experience_kb:
65-
request.tool_choice = "auto" if experience_kb.experience_active else "none"
65+
request.tool_choice = 'auto' if experience_kb.experience_active else 'none'
6666
generator = ctx.get_pipeline_mgr().get_active_pipeline().generator
6767
if generator:
6868
request.model = generator.model_id

EdgeCraftRAG/edgecraftrag/api/v1/data.py

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,88 +13,111 @@
1313

1414
# Upload a text or files
1515
@data_app.post(path="/v1/data")
16-
async def add_data(request: DataIn):
17-
pl = ctx.get_pipeline_mgr().get_active_pipeline()
16+
async def add_data(request: DataIn, docs_name: str = None):
17+
active_pl = ctx.get_pipeline_mgr().get_active_pipeline()
1818
docs = []
1919
if request.text is not None:
2020
docs.extend(ctx.get_file_mgr().add_text(text=request.text))
2121
if request.local_path is not None:
22-
docs.extend(ctx.get_file_mgr().add_files(docs=request.local_path))
22+
docs.extend(ctx.get_file_mgr().add_files(docs=request.local_path, docs_name=docs_name))
2323

2424
nodelist = ctx.get_pipeline_mgr().run_data_prepare(docs=docs)
25-
if pl.indexer.comp_subtype != "kbadmin_indexer":
25+
if active_pl.indexer.comp_subtype != "kbadmin_indexer":
2626
if nodelist is None or len(nodelist) == 0:
2727
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="File not found")
28-
ctx.get_node_mgr().add_nodes(pl.node_parser.idx, nodelist)
28+
ctx.get_node_mgr().add_nodes(active_pl.node_parser.idx, nodelist)
2929
return "Done"
3030

3131

3232
# Reindex all files
3333
@data_app.post(path="/v1/data/reindex")
3434
async def redindex_data():
3535
pl = ctx.get_pipeline_mgr().get_active_pipeline()
36-
36+
kb = ctx.get_knowledge_mgr().get_active_knowledge_base()
37+
if kb:
38+
kb_name = kb.name
39+
docs_name = kb_name + pl.name + str(pl.indexer.d)
40+
else:
41+
kb_name = None
42+
docs_name = None
3743
ctx.get_node_mgr().del_nodes_by_np_idx(pl.node_parser.idx)
38-
pl.indexer.reinitialize_indexer()
44+
pl.indexer.reinitialize_indexer(kb_name)
3945
pl.update_indexer_to_retriever()
4046

41-
all_docs = ctx.get_file_mgr().get_all_docs()
47+
all_docs = []
48+
docs_list =ctx.get_file_mgr().get_kb_files_by_name(docs_name)
49+
for docs_file in docs_list:
50+
all_docs.extend(docs_file.documents)
4251
nodelist = ctx.get_pipeline_mgr().run_data_prepare(docs=all_docs)
4352
if nodelist is not None and len(nodelist) > 0:
4453
ctx.get_node_mgr().add_nodes(pl.node_parser.idx, nodelist)
45-
4654
return "Done"
4755

4856

4957
# Upload files by a list of file_path
5058
@data_app.post(path="/v1/data/files")
5159
async def add_files(request: FilesIn):
5260
docs = []
61+
pl = ctx.get_pipeline_mgr().get_active_pipeline()
62+
kb = ctx.get_knowledge_mgr().get_active_knowledge_base()
63+
docs_name = kb.name + pl.name + str(pl.indexer.d)
5364
if request.local_paths is not None:
54-
docs.extend(ctx.get_file_mgr().add_files(docs=request.local_paths))
65+
docs.extend(ctx.get_file_mgr().add_files(docs=request.local_path, kb_name=docs_name))
5566

5667
nodelist = ctx.get_pipeline_mgr().run_data_prepare(docs=docs)
5768
if nodelist is None or len(nodelist) == 0:
5869
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="File not found")
59-
pl = ctx.get_pipeline_mgr().get_active_pipeline()
6070
ctx.get_node_mgr().add_nodes(pl.node_parser.idx, nodelist)
6171
return "Done"
6272

6373

6474
# GET files
6575
@data_app.get(path="/v1/data/files")
6676
async def get_files():
67-
return ctx.get_file_mgr().get_files()
77+
return ctx.get_file_mgr().get_all_docs()
6878

6979

7080
# GET a file
7181
@data_app.get(path="/v1/data/files/{name}")
72-
async def get_file_docs(name):
73-
return ctx.get_file_mgr().get_file_by_name_or_id(name)
82+
async def get_kb_files_by_name(name):
83+
return ctx.get_file_mgr().get_kb_files_by_name(name)
7484

7585

7686
# DELETE a file
7787
@data_app.delete(path="/v1/data/files/{name}")
78-
async def delete_file(name):
79-
if ctx.get_file_mgr().del_file(name):
80-
pl = ctx.get_pipeline_mgr().get_active_pipeline()
81-
88+
async def delete_file(kb_name, file_path):
89+
pl = ctx.get_pipeline_mgr().get_active_pipeline()
90+
docs_name = kb_name + pl.name + str(pl.indexer.d)
91+
if ctx.get_file_mgr().del_file(docs_name, file_path):
8292
# Current solution: reindexing all docs after deleting one file
8393
# TODO: delete the nodes related to the file
8494
ctx.get_node_mgr().del_nodes_by_np_idx(pl.node_parser.idx)
85-
pl.indexer.reinitialize_indexer()
95+
pl.indexer.reinitialize_indexer(kb_name)
8696
pl.update_indexer_to_retriever()
87-
88-
all_docs = ctx.get_file_mgr().get_all_docs()
97+
all_docs = ctx.get_file_mgr().get_file_by_name(docs_name)
8998
nodelist = ctx.get_pipeline_mgr().run_data_prepare(docs=all_docs)
9099
if nodelist is not None and len(nodelist) > 0:
91100
ctx.get_node_mgr().add_nodes(pl.node_parser.idx, nodelist)
92101

102+
return f"File is deleted"
103+
else:
104+
return f"File not found"
105+
106+
# DELETE a file
107+
@data_app.delete(path="/v1/data/all_files/{name}")
108+
async def delete_all_file(name):
109+
if ctx.get_file_mgr().del_kb_file(name):
110+
pl = ctx.get_pipeline_mgr().get_active_pipeline()
111+
112+
# Current solution: reindexing all docs after deleting one file
113+
# TODO: delete the nodes related to the file
114+
ctx.get_node_mgr().del_nodes_by_np_idx(pl.node_parser.idx)
115+
pl.indexer.reinitialize_indexer()
116+
pl.update_indexer_to_retriever()
93117
return f"File {name} is deleted"
94118
else:
95119
return f"File {name} not found"
96120

97-
98121
# Upload & save a file from UI
99122
@data_app.post(path="/v1/data/file/{file_name}")
100123
async def upload_file(file_name: str, file: UploadFile = File(...)):
@@ -122,4 +145,4 @@ async def upload_file(file_name: str, file: UploadFile = File(...)):
122145
except Exception as e:
123146
raise HTTPException(
124147
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Failed to upload file: {str(e)}"
125-
)
148+
)

0 commit comments

Comments
 (0)