Skip to content

Fix prep_docs not assigning auto-generated doc_ids to Document inputs#81

Open
lntutor wants to merge 1 commit into
AnswerDotAI:mainfrom
lntutor:fix/prep-docs-assign-autogen-ids
Open

Fix prep_docs not assigning auto-generated doc_ids to Document inputs#81
lntutor wants to merge 1 commit into
AnswerDotAI:mainfrom
lntutor:fix/prep-docs-assign-autogen-ids

Conversation

@lntutor

@lntutor lntutor commented Jul 19, 2026

Copy link
Copy Markdown

What's broken

When prep_docs receives a list of Document objects whose doc_id is None, it detects this, prints that it's reverting to auto-generated integer ids, and computes list(range(len(docs))) — but then throws that list away:

doc_ids = list(range(len(docs)))
# (never written back onto docs)

So every returned Document keeps doc_id=None:

prep_docs([Document(text="a"), Document(text="b"), Document(text="c")])
# doc_ids -> [None, None, None]   (expected [0, 1, 2])

Since the same Document object is placed into each Result (e.g. transformer_ranker.py), all results end up with doc_id=None, so RankedResults.get_score_by_docid(None) matches the first result for any query and no integer id resolves. The string-input path a few lines below already assigns list(range(len(docs))) correctly, so the two entry paths are inconsistent.

Fix

Write the generated ids back onto the documents, matching the string-input path.

Tests

Adds test_prep_docs_document_input_autogenerates_ids to tests/test_results.py. Full file passes (4).

When a list of Document objects with no doc_id is passed, prep_docs
detects the None ids, prints that it is reverting to auto-generated
integer ids, and computes list(range(len(docs))) -- but never writes them
back onto the documents. So every returned Document keeps doc_id=None,
and since the same Document object is placed into each Result, all results
end up with doc_id=None: get_score_by_docid(None) matches the first result
for any query and no integer id resolves. The string-input path already
assigns the ids correctly; this makes the Document-input path consistent.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N6RtoHuxrDqTUo9Mw9h4Cv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant