Skip to content

Commit

Permalink
Validating for broken index, with a test
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbraza committed Oct 9, 2024
1 parent 65660d4 commit c122640
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions paperqa/agents/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,10 @@ async def get_directory_index( # noqa: PLR0912
# NOTE: if the index was not previously built, its index_files will be empty.
# Otherwise, the index_files will not be empty
if not build:
if not await search_index.index_files:
raise RuntimeError(
f"Index {search_index.index_name} was empty, please rebuild it."
)
return search_index

if not sync_index_w_directory:
Expand Down
5 changes: 5 additions & 0 deletions tests/test_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ async def test_get_directory_index(agent_test_settings: Settings) -> None:
assert len(await index.index_files) == len(path_to_id) - 1
mock_aadd.assert_not_awaited(), "Expected we didn't re-add files"

# Note let's delete files.zip, and confirm we can't load the index
await (await index.file_index_filename).unlink()
with pytest.raises(RuntimeError, match="please rebuild"):
await get_directory_index(settings=agent_test_settings, build=False)


EXPECTED_STUB_DATA_FILES = {
"bates.txt",
Expand Down

0 comments on commit c122640

Please sign in to comment.