mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-10-04 04:04:14 +00:00
Address PR feedback: optimize logging and encapsulate document_id access
- Gate debug logging behind isEnabledFor check to avoid unnecessary computation - Add Chunk.document_id property to safely handle metadata/chunk_metadata extraction - Simplify RAG memory code using new property
This commit is contained in:
parent
a14f79a362
commit
2510bd349e
3 changed files with 24 additions and 11 deletions
|
@ -91,6 +91,22 @@ class Chunk(BaseModel):
|
|||
|
||||
return generate_chunk_id(str(uuid.uuid4()), str(self.content))
|
||||
|
||||
@property
|
||||
def document_id(self) -> str | None:
|
||||
"""Returns the document_id from either metadata or chunk_metadata, with metadata taking precedence."""
|
||||
# Check metadata first (takes precedence)
|
||||
doc_id = self.metadata.get("document_id")
|
||||
if isinstance(doc_id, str):
|
||||
return doc_id
|
||||
|
||||
# Fall back to chunk_metadata if available
|
||||
if self.chunk_metadata is not None:
|
||||
chunk_doc_id = getattr(self.chunk_metadata, "document_id", None)
|
||||
if isinstance(chunk_doc_id, str):
|
||||
return chunk_doc_id
|
||||
|
||||
return None
|
||||
|
||||
|
||||
@json_schema_type
|
||||
class QueryChunksResponse(BaseModel):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue