File tree Expand file tree Collapse file tree 3 files changed +24
-11
lines changed
providers/inline/tool_runtime/rag Expand file tree Collapse file tree 3 files changed +24
-11
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,22 @@ def chunk_id(self) -> str:
91
91
92
92
return generate_chunk_id (str (uuid .uuid4 ()), str (self .content ))
93
93
94
+ @property
95
+ def document_id (self ) -> str | None :
96
+ """Returns the document_id from either metadata or chunk_metadata, with metadata taking precedence."""
97
+ # Check metadata first (takes precedence)
98
+ doc_id = self .metadata .get ("document_id" )
99
+ if isinstance (doc_id , str ):
100
+ return doc_id
101
+
102
+ # Fall back to chunk_metadata if available
103
+ if self .chunk_metadata is not None :
104
+ chunk_doc_id = getattr (self .chunk_metadata , "document_id" , None )
105
+ if isinstance (chunk_doc_id , str ):
106
+ return chunk_doc_id
107
+
108
+ return None
109
+
94
110
95
111
@json_schema_type
96
112
class QueryChunksResponse (BaseModel ):
Original file line number Diff line number Diff line change 5
5
# the root directory of this source tree.
6
6
7
7
import asyncio
8
+ import logging
8
9
import uuid
9
10
from typing import Any
10
11
@@ -101,13 +102,12 @@ async def insert_chunks(
101
102
chunks : list [Chunk ],
102
103
ttl_seconds : int | None = None ,
103
104
) -> None :
104
- doc_ids = [
105
- getattr (chunk .chunk_metadata , "document_id" , None ) if chunk .chunk_metadata else None for chunk in chunks [:3 ]
106
- ]
107
- logger .debug (
108
- f"VectorIORouter.insert_chunks: { vector_db_id } , { len (chunks )} chunks, "
109
- f"ttl_seconds={ ttl_seconds } , chunk_ids={ doc_ids } { ' and more...' if len (chunks ) > 3 else '' } "
110
- )
105
+ if logger .isEnabledFor (logging .DEBUG ):
106
+ doc_ids = [chunk .document_id for chunk in chunks [:3 ]]
107
+ logger .debug (
108
+ f"VectorIORouter.insert_chunks: { vector_db_id } , { len (chunks )} chunks, "
109
+ f"ttl_seconds={ ttl_seconds } , chunk_ids={ doc_ids } { ' and more...' if len (chunks ) > 3 else '' } "
110
+ )
111
111
provider = await self .routing_table .get_provider_impl (vector_db_id )
112
112
await provider .insert_chunks (vector_db_id , chunks , ttl_seconds )
113
113
Original file line number Diff line number Diff line change @@ -279,10 +279,7 @@ async def query(
279
279
return RAGQueryResult (
280
280
content = picked ,
281
281
metadata = {
282
- "document_ids" : [
283
- c .metadata .get ("document_id" ) or (c .chunk_metadata .document_id if c .chunk_metadata else None )
284
- for c in chunks [: len (picked )]
285
- ],
282
+ "document_ids" : [c .document_id for c in chunks [: len (picked )]],
286
283
"chunks" : [c .content for c in chunks [: len (picked )]],
287
284
"scores" : scores [: len (picked )],
288
285
"vector_db_ids" : [c .metadata ["vector_db_id" ] for c in chunks [: len (picked )]],
You can’t perform that action at this time.
0 commit comments