Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/scripts/get_test_matrix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ for example in ${examples}; do
echo -e "Test supported hardware list: \n${hardware_list}"

run_hardware=""
if [[ $(printf '%s\n' "${changed_files[@]}" | grep ${example} | cut -d'/' -f2 | grep -E '\.py|Dockerfile*|ui|docker_image_build' ) ]]; then
if [[ $(printf '%s\n' "${changed_files[@]}" | grep ${example} | cut -d'/' -f2 | grep -E '\.py|Dockerfile*|ui|edgecraftrag|docker_image_build' ) ]]; then
echo "run test on all hardware if megaservice or ui code change..."
run_hardware=$hardware_list
elif [[ $(printf '%s\n' "${changed_files[@]}" | grep ${example} | grep 'tests'| cut -d'/' -f3 | grep -vE '^test_|^_test' ) ]]; then
Expand Down
Binary file added EdgeCraftRAG/assets/img/experience_access.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion EdgeCraftRAG/docker_compose/intel/gpu/arc/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ services:
ports:
- ${VLLM_SERVICE_PORT_B60:-8086}:${VLLM_SERVICE_PORT_B60:-8086}
volumes:
- ${MODEL_PATH}:/workspace/vllm/models
- ${MODEL_PATH-${PWD}}:/workspace/vllm/models
devices:
- /dev/dri:/dev/dri
environment:
Expand Down
2 changes: 1 addition & 1 deletion EdgeCraftRAG/docs/API_Guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Benchmarking activities may significantly reduce system performance.
export ENABLE_BENCHMARK="true"

# check the benchmark data for pipeline {pipeline_name}
curl -X GET http://${HOST_IP}:16010/v1/settings/pipelines/{pipeline_name}/benchmark -H "Content-Type: application/json" | jq '.'
curl -X GET http://${HOST_IP}:16010/v1/settings/pipelines/{pipeline_name}/benchmarks -H "Content-Type: application/json" | jq '.'
```

## Model Management
Expand Down
2 changes: 1 addition & 1 deletion EdgeCraftRAG/docs/Agentic_RAG_Guide_Zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ EC-RAG目前支持两种类型的智能体:
- **Simple Agent**: 不包含规划、research的简单轻量级Agent;
- **Deep Search Agent**: 能够进行多步规划、deep research和深度推理的更高级版本Agent。

## Retrieval
## 创建智能体

### 前提条件

Expand Down
55 changes: 55 additions & 0 deletions EdgeCraftRAG/docs/Experience_Guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# EC-RAG Experience Guide

This guide explains how to enable, configure, and use Experience capabilities within EdgeCraftRAG (EC-RAG). It covers the creation and management of experience to enhance the answer quality

## Overview

Experience refers to the knowledge and skills acquired through practical involvement, trial, and reflection, serving as a key foundation for solving real-world problems. In EC-RAG we now provide abilities to add such experience for the reference of your Chat.

Before use Experience, please make sure Milvus VectorDB is enabled and below env is set:

```bash
export METADATA_DATABASE_URL="http://${HOST_IP}:19530"
```

## Creating An Experience

Upon successful deployment of EC-RAG, we may navigate to `Knowledge Base` tab from the left panel:
![alt text](../assets/img/experience_access.png)

Then in the `Create Type Select` windows, choose `Go Create Experience`:
![alt text](../assets/img/experience_create_1.png)

In the next windws, we can set Experience to `Activated` or `Inactive`, this could also be changed after creation of Experience:
![alt text](../assets/img/experience_create_2.png)

## Managing Experiences

### Add Experiences

After successfully created `Experience`, Experience tab would be available with `Unique` tag:
![alt text](../assets/img/experience_management_1.png)

To add new experience, select `Create Experience` from the right panel:
![alt text](../assets/img/experience_management_2.png)

In the `Create Experience` window, we could add experience and its corresponding content as needed, multi experience creation is supported:
![alt text](../assets/img/experience_management_3.png)

### View and Edit Experiences

After experience added, they will be shown in list under `Experience` tab. We could toggle the `+` sign to show experience content details. Use the three dots next to `Experience` to activate or deactivate a Experience Base:
![alt text](../assets/img/experience_management_4.png)

## Examples

Here's a comparison with experience activated and not activated:

Without experience:
![alt text](../assets/img/experience_example_3.png)

Activated experience:
![alt text](../assets/img/experience_example_1.png)

RAG Answer:
![alt text](../assets/img/experience_example_2.png)
54 changes: 54 additions & 0 deletions EdgeCraftRAG/docs/Experience_Guide_Zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# EC-RAG 经验注入指南

本指南将为您介绍如何在 EdgeCraftRAG (EC-RAG) 中启用、配置和使用经验注入(Experience)功能,涵盖 Experience 的创建和管理,旨在提升您使用EC-RAG时的回答质量。

## 概述

Experience(经验)是指个人或团队在实践过程中积累的知识和技能,通常通过实际操作、试错和反思获得,是解决实际问题的重要依据。EC-RAG 现已支持添加此类Experience,为您的对话提供更多参考。
使用Experience之前,请确保Mivlus服务已经启动,并且请指定如下的环境变量:

```bash
export METADATA_DATABASE_URL="http://${HOST_IP}:19530"
```

## 创建 Experience

当 EC-RAG 被正确部署后,您可以通过左侧面板的`知识库`(Knowledge Base)选项卡切换到Experience创建页面:
![alt text](../assets/img/experience_access_zh.png)

然后在`创建类型选择`窗口中,选择`去创建经验注入`
![alt text](../assets/img/experience_create_1_zh.png)

在接下来的窗口中,您可以将 Experience 设置为`已启用``已停用`状态。请注意,这也可以在创建 Experience 后进行更改:
![alt text](../assets/img/experience_create_2_zh.png)

## 管理 Experience

成功创建`Experience`后,左侧面板会出现`Experience`选项卡,同时带有`唯一`标签:
![alt text](../assets/img/experience_management_1_zh.png)

### 添加 Experience

当您需要添加新 Experience 时,请从右侧面板选择`新建经验`
![alt text](../assets/img/experience_management_2_zh.png)

`新建经验`窗口中,您可以根据需要添加经验及其对应的内容,EC-RAG 支持创建多个经验条目:
![alt text](../assets/img/experience_management_3_zh.png)

### 查看与修改

添加经验后,它们将以列表形式显示在`经验`选项卡下。您可以点击`+`号展开查看 Experience 内容的详细信息。使用左侧面板里`Experience`旁边的三个点可以激活或停用某个 Experience 库:
![alt text](../assets/img/experience_management_4_zh.png)

## 使用示例

以下是激活和未激活Experience库的对比:

未激活Experience:
![alt text](../assets/img/experience_example_3.png)

激活Experience:
![alt text](../assets/img/experience_example_1.png)

RAG回答:
![alt text](../assets/img/experience_example_2.png)
43 changes: 0 additions & 43 deletions EdgeCraftRAG/docs/Query_Search_Zh.md

This file was deleted.

2 changes: 1 addition & 1 deletion EdgeCraftRAG/edgecraftrag/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
26.01-Dev
26.01-Release
45 changes: 44 additions & 1 deletion EdgeCraftRAG/edgecraftrag/api/v1/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import time

from edgecraftrag.api.v1.knowledge_base import Synchronizing_vector_data
from edgecraftrag.api_schema import AgentCreateIn
from edgecraftrag.base import AgentType
from edgecraftrag.config_repository import MilvusConfigRepository, save_agent_configurations
Expand All @@ -22,12 +23,14 @@ async def get_all_agents():
agents = ctx.get_agent_mgr().get_agents()
active_id = ctx.get_agent_mgr().get_active_agent_id()
for k, agent in agents.items():
pipeline_name = ctx.get_pipeline_mgr().get_pipeline_by_name_or_id(agent.pipeline_idx).name
out.append(
AgentCreateIn(
idx=agent.idx,
name=agent.name,
type=agent.comp_subtype,
pipeline_idx=agent.pipeline_idx,
pipeline_name=pipeline_name,
configs=agent.configs,
active=True if agent.idx == active_id else False,
)
Expand All @@ -40,12 +43,14 @@ async def get_all_agents():
async def get_agent(name):
agent = ctx.get_agent_mgr().get_agent_by_name(name)
if agent:
pipeline_name = ctx.get_pipeline_mgr().get_pipeline_by_name_or_id(agent.pipeline_idx).name
isactive = True if agent.idx == ctx.get_agent_mgr().get_active_agent_id() else False
return AgentCreateIn(
idx=agent.idx,
name=agent.name,
type=agent.comp_subtype,
pipeline_idx=agent.pipeline_idx,
pipeline_name=pipeline_name,
configs=agent.configs,
active=isactive,
)
Expand All @@ -70,10 +75,15 @@ async def create_agent(request: AgentCreateIn, status_code=status.HTTP_201_CREAT
async def update_agent(name, request: AgentCreateIn):
try:
agentmgr = ctx.get_agent_mgr()
if agentmgr.get_agent_by_name(name):
agent = agentmgr.get_agent_by_name(name)
if agent:
ret = agentmgr.update_agent(name, request)
if ret:
await save_agent_configurations("update", ctx.get_agent_mgr().get_agents())
# manage agent bound pipeline status, trigger kb indexing if needed
# can be removed once kb indexing is decoupled from pipeline
pl_idx = agent.pipeline_idx
await manage_agent_bound_pipeline(pl_idx, request)
return ret
else:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
Expand Down Expand Up @@ -146,3 +156,36 @@ async def load_agent(request: AgentCreateIn):
agentmgr.remove_agent_by_name(request.name)
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e))
return agent


async def manage_agent_bound_pipeline(bound_pl_idx, request):
# case1: activate agent, while bound pipeline is not active -> activate it, cache previous active pipeline if exists
# case2: activate agent, while bound pipeline is already active -> still call activate, for caching current pipeline
# case3: deactivate agent, while bound pipeline **was** active -> do NOT deactivate bound pipeline, do nothing
# case4: deactivate agent, while bound pipeline **was NOT** active -> deactivate bound pipeline, activate previous active pipeline if exists
pl_manager = ctx.get_pipeline_mgr()
prev_active_pipeline = pl_manager.get_active_pipeline()

active_kb = ctx.knowledgemgr.get_active_knowledge_base()
kb_name = active_kb.name if active_kb else "default"

if request.active:
pl_manager.activate_pipeline(bound_pl_idx, request.active, ctx.get_node_mgr(), kb_name, cache_prev=True)
else:
# at deactivate, prev_active_pl can be 1.other pl/2.None/3.current bound_pl
prev_active_pl = pl_manager.get_prev_active_pipeline_name()
if prev_active_pl and prev_active_pl != bound_pl_idx:
# 1, restore to the other pipeline activated
pl_manager.activate_pipeline(prev_active_pl, True, ctx.get_node_mgr(), kb_name)
elif not prev_active_pl:
# 2, deactivate current bound pipeline, leave no active pipeline as before
pl_manager.activate_pipeline(bound_pl_idx, False, ctx.get_node_mgr(), kb_name)
else:
# 3, do nothing
pass
# when agent is deactivated, clear cached previous active pipeline
pl_manager.clear_prev_active_pipeline_name()

cur_active_pipeline = pl_manager.get_active_pipeline()
if prev_active_pipeline and cur_active_pipeline and prev_active_pipeline.idx != cur_active_pipeline.idx:
await Synchronizing_vector_data(prev_active_pipeline, cur_active_pipeline)
19 changes: 12 additions & 7 deletions EdgeCraftRAG/edgecraftrag/api/v1/chatqna.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import requests
from comps.cores.proto.api_protocol import ChatCompletionRequest
from edgecraftrag.api_schema import RagOut
from edgecraftrag.base import GeneratorType
from edgecraftrag.context import ctx
from edgecraftrag.utils import chain_async_generators, serialize_contexts, stream_generator
from fastapi import Body, FastAPI, HTTPException, status
Expand Down Expand Up @@ -52,19 +53,21 @@ async def chatqna(request: ChatCompletionRequest):
if experience_kb:
request.tool_choice = "auto" if experience_kb.experience_active else "none"

request.input = ctx.get_session_mgr().concat_history(
sessionid, active_pl.generator.inference_type, request.messages
)
generator = active_pl.get_generator(GeneratorType.CHATQNA)
inference_type = generator.inference_type if generator else "local"

request.input = ctx.get_session_mgr().concat_history(sessionid, inference_type, request.messages)

# Run agent if activated, otherwise, run pipeline
if ctx.get_agent_mgr().get_active_agent():
run_agent_gen = await ctx.get_agent_mgr().run_agent(chat_request=request)
return StreamingResponse(save_session(sessionid, run_agent_gen), media_type="text/plain")

else:
generator = active_pl.generator
if generator:
request.model = generator.model_id
generator = active_pl.get_generator(GeneratorType.CHATQNA)
if not generator:
raise Exception("code:0000Please make sure chatqna generator is available in pipeline.")
request.model = generator.model_id

if request.stream:
run_pipeline_gen, contexts = await ctx.get_pipeline_mgr().run_pipeline(chat_request=request)
Expand All @@ -75,6 +78,8 @@ async def chatqna(request: ChatCompletionRequest):
return str(ret)

except Exception as e:
if "code:0000" in str(e):
return str(e)
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail=f"ChatQnA Error: {e}",
Expand All @@ -91,7 +96,7 @@ async def ragqna(request: ChatCompletionRequest):
request.user = active_kb if active_kb else None
if experience_kb:
request.tool_choice = "auto" if experience_kb.experience_active else "none"
generator = ctx.get_pipeline_mgr().get_active_pipeline().generator
generator = ctx.get_pipeline_mgr().get_active_pipeline().get_generator(GeneratorType.CHATQNA)
if generator:
request.model = generator.model_id
if request.stream:
Expand Down
Loading
Loading