refactor(chunks): order chunk reads by (document_id, position)

Presentation and citation ordering moves off Chunk.id/created_at to the
explicit position column (id kept as tiebreaker). Vector and ts_rank
ranking order_by clauses are untouched.
This commit is contained in:
CREDO23 2026-06-12 18:53:21 +02:00
parent 5a71769dba
commit 052e9ef4d1
9 changed files with 28 additions and 19 deletions

View file

@ -156,7 +156,7 @@ async def _resolve_document_text(
stmt = (
select(Chunk.content)
.where(Chunk.document_id == document.id)
.order_by(Chunk.id)
.order_by(Chunk.position, Chunk.id)
.limit(_MAX_CHUNKS_FOR_CONTEXT)
)
result = await session.execute(stmt)

View file

@ -62,7 +62,7 @@ async def _get_document_markdown(
chunk_result = await session.execute(
select(Chunk.content)
.filter(Chunk.document_id == document.id)
.order_by(Chunk.id)
.order_by(Chunk.position, Chunk.id)
)
chunks = chunk_result.scalars().all()
if chunks: