Skip to content

Commit ed7b473

Browse files
fix: Setting default value for metadata_token_count in case the key is not found (#2199)
# What does this PR do? If a user has previously serialized data into their vector store without the `metadata_token_count` in the chunk, the `query` method will fail in a server error. This fixes that edge case by returning 0 when the key is not detected. This solution is suboptimal but I think it's better to understate the token size rather than recalculate it and add unnecessary complexity to the retrieval code. [//]: # (If resolving an issue, uncomment and update the line below) [//]: # (Closes #[issue-number]) ## Test Plan [Describe the tests you ran to verify your changes with result summaries. *Provide clear instructions so the plan can be easily re-executed.*] [//]: # (## Documentation) Signed-off-by: Francisco Javier Arceo <[email protected]>
1 parent 6d20b72 commit ed7b473

File tree

1 file changed

+1
-1
lines changed
  • llama_stack/providers/inline/tool_runtime/rag

1 file changed

+1
-1
lines changed

llama_stack/providers/inline/tool_runtime/rag/memory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ async def query(
146146
for i, chunk in enumerate(chunks):
147147
metadata = chunk.metadata
148148
tokens += metadata["token_count"]
149-
tokens += metadata["metadata_token_count"]
149+
tokens += metadata.get("metadata_token_count", 0)
150150

151151
if tokens > query_config.max_tokens_in_context:
152152
log.error(

0 commit comments

Comments
 (0)