mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-10-10 21:26:01 +02:00
18 lines
493 B
Python
18 lines
493 B
Python
from collections.abc import Sequence
|
|
|
|
from danswer.chat.models import LlmDoc
|
|
from danswer.indexing.models import InferenceChunk
|
|
|
|
|
|
def map_document_id_order(
|
|
chunks: Sequence[InferenceChunk | LlmDoc], one_indexed: bool = True
|
|
) -> dict[str, int]:
|
|
order_mapping = {}
|
|
current = 1 if one_indexed else 0
|
|
for chunk in chunks:
|
|
if chunk.document_id not in order_mapping:
|
|
order_mapping[chunk.document_id] = current
|
|
current += 1
|
|
|
|
return order_mapping
|