Merge remote-tracking branch 'origin/main' into agent-update

This commit is contained in:
Wenjie Zhang 2025-04-04 18:34:49 +08:00
parent f3707c34bc
commit 42384236f8
5 changed files with 59 additions and 4 deletions

View File

@ -0,0 +1,35 @@
---
name: 提交一个BUG
about: 提交一个 BUG
title: "[BUG]"
labels: bug
assignees: xerrors
---
### 描述这个 bug
简单描述一下这个 BUG
### 如何复现
什么情况下出现:
### 相关信息
**1检查 `docker logs`**
请运行以下命令,并提供部分相关日志:
```sh
docker logs --tail=100 api-dev
```
如果问题与模型调用相关,请尝试切换到其他在线模型
**2相关截图**
**3其他相关信息**

View File

@ -61,6 +61,7 @@ services:
- NEO4J_AUTH=neo4j/0123456789
- NEO4J_server_bolt_listen__address=0.0.0.0:7687
- NEO4J_server_http_listen__address=0.0.0.0:7474
- ENTITY_EMBEDDING=true
networks:
- app-network

View File

@ -218,7 +218,19 @@ class GraphDatabase:
def query_by_vector(self, entity_name, threshold=0.9, kgdb_name='neo4j', hops=2, num_of_res=5):
self.use_database(kgdb_name)
def _index_exists(tx, index_name):
"""检查索引是否存在"""
result = tx.run("SHOW INDEXES")
for record in result:
if record["name"] == index_name:
return True
return False
def query(tx, text):
# 首先检查索引是否存在
if not _index_exists(tx, "entityEmbeddings"):
raise Exception("向量索引不存在,请先创建索引")
embedding = self.get_embedding(text)
result = tx.run("""
CALL db.index.vector.queryNodes('entityEmbeddings', 10, $embedding)
@ -227,9 +239,14 @@ class GraphDatabase:
""", embedding=embedding)
return result.values()
with self.driver.session() as session:
results = session.execute_read(query, entity_name)
try:
with self.driver.session() as session:
results = session.execute_read(query, entity_name)
except Exception as e:
if "向量索引不存在" in str(e):
logger.error(f"向量索引不存在,请先创建索引: {e}, {traceback.format_exc()}")
return []
raise e
# 筛选出分数高于阈值的实体
qualified_entities = [result[0] for result in results[:num_of_res] if result[1] > threshold]

View File

@ -76,6 +76,8 @@ class Retriever:
results = []
if refs["meta"].get("use_graph") and config.enable_knowledge_base:
for entity in refs["entities"]:
if entity == "":
continue
result = graph_base.query_by_vector(entity)
if result != []:
results.extend(result)

View File

@ -434,7 +434,7 @@ const fetchChatResponse = (user_input, cur_res_id) => {
const params = {
query: user_input,
history: getHistory(),
history: getHistory().slice(0, -1), // ,
meta: meta,
cur_res_id: cur_res_id,
}