Skip to content

Commit e6c2e4f

Browse files
committed
feat: enhance knowledge retrieval with JSON metadata support
1 parent 3498d79 commit e6c2e4f

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

apps/knowledge/serializers/knowledge.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import io
2+
import json
23
import logging
34
import os
45
import re
@@ -288,9 +289,11 @@ def one(self):
288289
'folder_query_set': QuerySet(KnowledgeFolder)
289290
}
290291
all_application_list = [str(adm.get('id')) for adm in self.list_application(with_valid=False)]
292+
knowledge_dict = native_search(query_set_dict, select_string=get_file_content(
293+
os.path.join(PROJECT_DIR, "apps", "knowledge", 'sql', 'list_knowledge.sql')), with_search_one=True)
291294
return {
292-
**native_search(query_set_dict, select_string=get_file_content(
293-
os.path.join(PROJECT_DIR, "apps", "knowledge", 'sql', 'list_knowledge.sql')), with_search_one=True),
295+
**knowledge_dict,
296+
'meta': json.loads(knowledge_dict.get('meta', '{}')),
294297
'application_id_list': list(filter(
295298
lambda application_id: all_application_list.__contains__(application_id),
296299
[

apps/knowledge/sql/list_knowledge.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ FROM (SELECT "temp_knowledge".id::text, "temp_knowledge".name,
1313
"temp_knowledge"."scope",
1414
"temp_knowledge"."embedding_model_id"::text,
1515
"document_temp"."char_length",
16+
to_json("temp_knowledge".meta)::jsonb as meta,
1617
CASE
1718
WHEN
1819
"app_knowledge_temp"."count" IS NULL THEN 0
@@ -43,6 +44,7 @@ FROM (SELECT "temp_knowledge".id::text, "temp_knowledge".name,
4344
'WORKSPACE' as "scope",
4445
'' as "embedding_model_id",
4546
0 as char_length,
47+
'{}'::jsonb as meta,
4648
0 as application_mapping_count,
4749
0 as document_count
4850
from knowledge_folder ${folder_query_set}) temp

0 commit comments

Comments
 (0)