evan-danswer b7da91e3ae
improved basic search latency (#4186)
* improved basic search latency

* address PR comments + minor cleanup
2025-03-06 22:22:59 +00:00

42 lines
1.4 KiB
Python

from onyx.chat.models import LlmDoc
from onyx.chat.models import OnyxContext
from onyx.context.search.models import InferenceSection
from onyx.prompts.prompt_utils import clean_up_source
def llm_doc_to_dict(llm_doc: LlmDoc, doc_num: int) -> dict:
doc_dict = {
"document_number": doc_num + 1,
"title": llm_doc.semantic_identifier,
"content": llm_doc.content,
"source": clean_up_source(llm_doc.source_type),
"metadata": llm_doc.metadata,
}
if llm_doc.updated_at:
doc_dict["updated_at"] = llm_doc.updated_at.strftime("%B %d, %Y %H:%M")
return doc_dict
def section_to_dict(section: InferenceSection, section_num: int) -> dict:
doc_dict = {
"document_number": section_num + 1,
"title": section.center_chunk.semantic_identifier,
"content": section.combined_content,
"source": clean_up_source(section.center_chunk.source_type),
"metadata": section.center_chunk.metadata,
}
if section.center_chunk.updated_at:
doc_dict["updated_at"] = section.center_chunk.updated_at.strftime(
"%B %d, %Y %H:%M"
)
return doc_dict
def context_from_inference_section(section: InferenceSection) -> OnyxContext:
return OnyxContext(
content=section.combined_content,
document_id=section.center_chunk.document_id,
semantic_identifier=section.center_chunk.semantic_identifier,
blurb=section.center_chunk.blurb,
)