feat: enhance knowledge retrieval with JSON metadata support
This commit is contained in:
parent
3498d799cf
commit
e6c2e4fb13
@ -1,4 +1,5 @@
|
|||||||
import io
|
import io
|
||||||
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
@ -288,9 +289,11 @@ class KnowledgeSerializer(serializers.Serializer):
|
|||||||
'folder_query_set': QuerySet(KnowledgeFolder)
|
'folder_query_set': QuerySet(KnowledgeFolder)
|
||||||
}
|
}
|
||||||
all_application_list = [str(adm.get('id')) for adm in self.list_application(with_valid=False)]
|
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 {
|
return {
|
||||||
**native_search(query_set_dict, select_string=get_file_content(
|
**knowledge_dict,
|
||||||
os.path.join(PROJECT_DIR, "apps", "knowledge", 'sql', 'list_knowledge.sql')), with_search_one=True),
|
'meta': json.loads(knowledge_dict.get('meta', '{}')),
|
||||||
'application_id_list': list(filter(
|
'application_id_list': list(filter(
|
||||||
lambda application_id: all_application_list.__contains__(application_id),
|
lambda application_id: all_application_list.__contains__(application_id),
|
||||||
[
|
[
|
||||||
|
|||||||
@ -13,6 +13,7 @@ FROM (SELECT "temp_knowledge".id::text, "temp_knowledge".name,
|
|||||||
"temp_knowledge"."scope",
|
"temp_knowledge"."scope",
|
||||||
"temp_knowledge"."embedding_model_id"::text,
|
"temp_knowledge"."embedding_model_id"::text,
|
||||||
"document_temp"."char_length",
|
"document_temp"."char_length",
|
||||||
|
to_json("temp_knowledge".meta)::jsonb as meta,
|
||||||
CASE
|
CASE
|
||||||
WHEN
|
WHEN
|
||||||
"app_knowledge_temp"."count" IS NULL THEN 0
|
"app_knowledge_temp"."count" IS NULL THEN 0
|
||||||
@ -43,6 +44,7 @@ FROM (SELECT "temp_knowledge".id::text, "temp_knowledge".name,
|
|||||||
'WORKSPACE' as "scope",
|
'WORKSPACE' as "scope",
|
||||||
'' as "embedding_model_id",
|
'' as "embedding_model_id",
|
||||||
0 as char_length,
|
0 as char_length,
|
||||||
|
'{}'::jsonb as meta,
|
||||||
0 as application_mapping_count,
|
0 as application_mapping_count,
|
||||||
0 as document_count
|
0 as document_count
|
||||||
from knowledge_folder ${folder_query_set}) temp
|
from knowledge_folder ${folder_query_set}) temp
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user