feat: enhance knowledge retrieval with JSON metadata support

This commit is contained in:
CaptainB 2025-06-18 16:09:53 +08:00
parent 3498d799cf
commit e6c2e4fb13
2 changed files with 7 additions and 2 deletions

View File

@ -1,4 +1,5 @@
import io
import json
import logging
import os
import re
@ -288,9 +289,11 @@ class KnowledgeSerializer(serializers.Serializer):
'folder_query_set': QuerySet(KnowledgeFolder)
}
all_application_list = [str(adm.get('id')) for adm in self.list_application(with_valid=False)]
knowledge_dict = native_search(query_set_dict, select_string=get_file_content(
os.path.join(PROJECT_DIR, "apps", "knowledge", 'sql', 'list_knowledge.sql')), with_search_one=True)
return {
**native_search(query_set_dict, select_string=get_file_content(
os.path.join(PROJECT_DIR, "apps", "knowledge", 'sql', 'list_knowledge.sql')), with_search_one=True),
**knowledge_dict,
'meta': json.loads(knowledge_dict.get('meta', '{}')),
'application_id_list': list(filter(
lambda application_id: all_application_list.__contains__(application_id),
[

View File

@ -13,6 +13,7 @@ FROM (SELECT "temp_knowledge".id::text, "temp_knowledge".name,
"temp_knowledge"."scope",
"temp_knowledge"."embedding_model_id"::text,
"document_temp"."char_length",
to_json("temp_knowledge".meta)::jsonb as meta,
CASE
WHEN
"app_knowledge_temp"."count" IS NULL THEN 0
@ -43,6 +44,7 @@ FROM (SELECT "temp_knowledge".id::text, "temp_knowledge".name,
'WORKSPACE' as "scope",
'' as "embedding_model_id",
0 as char_length,
'{}'::jsonb as meta,
0 as application_mapping_count,
0 as document_count
from knowledge_folder ${folder_query_set}) temp