RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
Fix metadata in get_list() (#12906)
qinling0210212d6f36604d
diff --git a/api/db/services/doc_metadata_service.py b/api/db/services/doc_metadata_service.pyindex 98820f9069..bca9ef1e09 100644--- a/api/db/services/doc_metadata_service.py+++ b/api/db/services/doc_metadata_service.py@@ -28,6 +28,8 @@ from typing import Dict, List, Optionalfrom api.db.db_models import DB, Documentfrom common import settingsfrom common.metadata_utils import dedupe_list+from api.db.db_models import Knowledgebase+from common.doc_store.doc_store_base import OrderByExprclass DocMetadataService:@@ -57,7 +59,7 @@ class DocMetadataService:Returns:Simple metadata dictionary"""- if not flat_meta:+ if not flat_meta or not isinstance(flat_meta, dict):return {}meta_fields = flat_meta.get('meta_fields')@@ -158,9 +160,6 @@ class DocMetadataService:Returns:Search results from ES/Infinity"""- from api.db.db_models import Knowledgebase- from common.doc_store.doc_store_base import OrderByExpr-kb = Knowledgebase.get_by_id(kb_id)if not kb:return None@@ -247,8 +246,6 @@ class DocMetadataService:True if successful, False otherwise"""try:- from api.db.db_models import Knowledgebase-# Get document with tenant_id (need to join with Knowledgebase)doc_query = Document.select(Document, Knowledgebase.tenant_id).join(Knowledgebase, on=(Knowledgebase.id == Document.kb_id)@@ -304,7 +301,14 @@ class DocMetadataService:if result:logging.error(f"Failed to insert metadata for document {doc_id}: {result}")return False-+ # Force ES refresh to make metadata immediately available for search+ if not settings.DOC_ENGINE_INFINITY:+ try:+ settings.docStoreConn.es.indices.refresh(index=index_name)+ logging.debug(f"Refreshed metadata index: {index_name}")+ except Exception as e:+ logging.warning(f"Failed to refresh metadata index {index_name}: {e}")+logging.debug(f"Successfully inserted metadata for document {doc_id}")return True@@ -329,8 +333,6 @@ class DocMetadataService:True if successful, False otherwise"""try:- from api.db.db_models import Knowledgebase-# Get document with tenant_iddoc_query = Document.select(Document, Knowledgebase.tenant_id).join(Knowledgebase, on=(Knowledgebase.id == Document.kb_id)@@ -394,10 +396,7 @@ class DocMetadataService:True if successful (or no metadata to delete), False otherwise"""try:- from api.db.db_models import Knowledgebase-logging.debug(f"[METADATA DELETE] Starting metadata deletion for document: {doc_id}")-# Get document with tenant_iddoc_query = Document.select(Document, Knowledgebase.tenant_id).join(Knowledgebase, on=(Knowledgebase.id == Document.kb_id)@@ -494,8 +493,6 @@ class DocMetadataService:except Exception as e:logging.warning(f"[DROP EMPTY TABLE] Count API failed, falling back to search: {e}")# Fallback to search if count fails- from common.doc_store.doc_store_base import OrderByExpr-results = settings.docStoreConn.search(select_fields=["id"],highlight_fields=[],@@ -564,8 +561,6 @@ class DocMetadataService:Metadata dictionary, empty dict if not found"""try:- from api.db.db_models import Knowledgebase-# Get document with tenant_iddoc_query = Document.select(Document, Knowledgebase.tenant_id).join(Knowledgebase, on=(Knowledgebase.id == Document.kb_id)@@ -618,9 +613,6 @@ class DocMetadataService:Metadata dictionary in format: {field_name: {value: [doc_ids]}}"""try:- from api.db.db_models import Knowledgebase- from common.doc_store.doc_store_base import OrderByExpr-# Get tenant_id from first KBkb = Knowledgebase.get_by_id(kb_ids[0])if not kb:@@ -697,9 +689,6 @@ class DocMetadataService:Metadata dictionary in format: {field_name: {value: [doc_ids]}}"""try:- from api.db.db_models import Knowledgebase- from common.doc_store.doc_store_base import OrderByExpr-# Get tenant_id from first KBkb = Knowledgebase.get_by_id(kb_ids[0])if not kb:diff --git a/api/db/services/document_service.py b/api/db/services/document_service.pyindex 4f015ddd58..aa532af625 100644--- a/api/db/services/document_service.py+++ b/api/db/services/document_service.py@@ -109,7 +109,12 @@ class DocumentService(CommonService):count = docs.count()docs = docs.paginate(page_number, items_per_page)- return list(docs.dicts()), count++ docs_list = list(docs.dicts())+ metadata_map = DocMetadataService.get_metadata_for_documents(None, kb_id)+ for doc in docs_list:+ doc["meta_fields"] = metadata_map.get(doc["id"], {})+ return docs_list, count@classmethod@DB.connection_context()