Skip to content

Commit

Permalink
Do not log error when we are being optimisting about field presence o…
Browse files Browse the repository at this point in the history
…n rag strategy prompt building
  • Loading branch information
lferran committed Jul 26, 2024
1 parent 29e58ec commit 241f6bb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
7 changes: 6 additions & 1 deletion nucliadb/src/nucliadb/search/search/chat/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,10 @@ async def get_resource_field_extracted_text(
try:
field_type, field_key = field_id.strip("/").split("/")
except ValueError:
logger.error(f"Invalid field id: {field_id}. Skipping getting extracted text.")
logger.info(
f"Invalid field id: {field_id}. Skipping getting extracted text.",
extra={"kbid": kb_obj.kbid},
)
return None
field = await resource.get_field(field_key, KB_REVERSE[field_type], load=False)
if field is None:
Expand Down Expand Up @@ -389,6 +392,7 @@ async def hierarchy_prompt_context(
start=0,
end=500,
extracted_text_cache=etcache,
log_on_missing_field=False,
)
summary_text = await paragraphs.get_paragraph_text(
kbid=kbid,
Expand All @@ -397,6 +401,7 @@ async def hierarchy_prompt_context(
start=0,
end=1000,
extracted_text_cache=etcache,
log_on_missing_field=False,
)
resources[rid] = ExtraCharsParagraph(
title=title_text,
Expand Down
27 changes: 16 additions & 11 deletions nucliadb/src/nucliadb/search/search/paragraphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ async def get_paragraph_from_full_text(
end: int,
split: Optional[str] = None,
extracted_text_cache: Optional[ExtractedTextCache] = None,
log_on_missing_field: bool = True,
) -> str:
"""
Pull paragraph from full text stored in database.
Expand All @@ -125,13 +126,14 @@ async def get_paragraph_from_full_text(
"""
extracted_text = await get_field_extracted_text(field, cache=extracted_text_cache)
if extracted_text is None:
logger.warning(
"Extracted_text for field does not exist on DB. This should not happen.",
extra={
"field_id": field.resource_unique_id,
"kbid": field.kbid,
},
)
if log_on_missing_field:
logger.warning(
"Extracted_text for field does not exist on DB. This should not happen.",
extra={
"field_id": field.resource_unique_id,
"kbid": field.kbid,
},
)
return ""

if split not in (None, ""):
Expand All @@ -156,14 +158,16 @@ async def get_paragraph_text(
ResourceORM
] = None, # allow passing in orm_resource to avoid extra DB calls or txn issues
extracted_text_cache: Optional[ExtractedTextCache] = None,
log_on_missing_field: bool = True,
) -> str:
if orm_resource is None:
orm_resource = await get_resource_from_cache(kbid, rid)
if orm_resource is None:
logger.warning(
"Resource does not exist on DB. This should not happen.",
extra={"resource_id": rid, "kbid": kbid, "field": field},
)
if log_on_missing_field:
logger.warning(
"Resource does not exist on DB. This should not happen.",
extra={"resource_id": rid, "kbid": kbid, "field": field},
)
return ""

_, field_type, field = field.split("/")
Expand All @@ -176,6 +180,7 @@ async def get_paragraph_text(
end=end,
split=split,
extracted_text_cache=extracted_text_cache,
log_on_missing_field=log_on_missing_field,
)

if highlight:
Expand Down

0 comments on commit 241f6bb

Please sign in to comment.