Toggle navigation
Toggle navigation
This project
Loading...
Sign in
万朱浩
/
Venue-Ops
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
马一丁
2025-12-19 15:42:58 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
bbf8d334efb654b7b237ba81d362f96ce659f96a
bbf8d334
1 parent
f67ebb00
Optimize GraphRAG query logs
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
0 deletions
app.py
app.py
View file @
bbf8d33
...
...
@@ -400,6 +400,36 @@ def append_knowledge_log(source: str, payload: dict):
logger
.
warning
(
f
"Knowledge Query: 写日志失败: {exc}"
)
def
_trim_text
(
text
:
str
,
limit
:
int
=
300
)
->
str
:
text
=
_sanitize_log_text
(
text
)
return
text
if
len
(
text
)
<=
limit
else
text
[:
limit
]
+
"..."
def
_compact_records
(
items
):
"""将节点/记录压缩为简洁日志格式,避免污染。"""
compacted
=
[]
if
not
items
:
return
compacted
for
item
in
items
:
if
not
isinstance
(
item
,
dict
):
compacted
.
append
(
_trim_text
(
str
(
item
)))
continue
entry
=
{}
for
key
,
value
in
item
.
items
():
# 仅记录必要字段,其他字段做字符串压缩
if
isinstance
(
value
,
(
str
,
int
,
float
,
bool
)):
entry
[
key
]
=
_trim_text
(
str
(
value
))
else
:
try
:
entry
[
key
]
=
_trim_text
(
json
.
dumps
(
value
,
ensure_ascii
=
False
))
except
Exception
:
entry
[
key
]
=
_trim_text
(
str
(
value
))
compacted
.
append
(
entry
)
return
compacted
# 初始化 knowledge_query.log
init_knowledge_log
()
...
...
@@ -1551,6 +1581,25 @@ def query_graph():
)
result
=
query_engine
.
query
(
params
)
try
:
append_knowledge_log
(
'GRAPH_QUERY_RESULT'
,
{
'report_id'
:
report_id
or
'latest'
,
'counts'
:
{
'matched_sections'
:
len
(
result
.
matched_sections
),
'matched_queries'
:
len
(
result
.
matched_queries
),
'matched_sources'
:
len
(
result
.
matched_sources
),
'total_nodes'
:
result
.
total_nodes
,
},
'query_params'
:
result
.
query_params
,
'matched_sections'
:
_compact_records
(
result
.
matched_sections
),
'matched_queries'
:
_compact_records
(
result
.
matched_queries
),
'matched_sources'
:
_compact_records
(
result
.
matched_sources
),
}
)
except
Exception
as
log_exc
:
# pragma: no cover - 日志失败不阻塞主流程
logger
.
warning
(
f
\
"Knowledge Query: 结果写日志失败: {log_exc}
\"
)
return jsonify({
'success': True,
...
...
Please
register
or
login
to post a comment