Skip to content

Commit

Permalink
Made it clear what is a search index and what is an answers index
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbraza committed Oct 1, 2024
1 parent fb2ea23 commit 5e01fa5
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions paperqa/agents/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async def agent_query(
if docs is None:
docs = Docs()

search_index = SearchIndex(
answers_index = SearchIndex(
fields=[*SearchIndex.REQUIRED_FIELDS, "question"],
index_name="answers",
index_directory=query.settings.agent.index.index_directory,
Expand All @@ -63,15 +63,15 @@ async def agent_query(

agent_logger.info(f"[bold blue]Answer: {response.answer.answer}[/bold blue]")

await search_index.add_document(
await answers_index.add_document(
{
"file_location": str(response.answer.id),
"body": response.answer.answer,
"question": response.answer.question,
},
document=response,
)
await search_index.save_index()
await answers_index.save_index()
return response


Expand Down Expand Up @@ -290,7 +290,7 @@ async def index_search(
fields = [*SearchIndex.REQUIRED_FIELDS]
if index_name == "answers":
fields.append("question")
search_index = SearchIndex(
search_or_answers_index = SearchIndex(
fields=fields,
index_name=index_name,
index_directory=index_directory,
Expand All @@ -303,15 +303,15 @@ async def index_search(

results = [
(AnswerResponse(**a[0]) if index_name == "answers" else a[0], a[1])
for a in await search_index.query(query=query, keep_filenames=True)
for a in await search_or_answers_index.query(query=query, keep_filenames=True)
]

if results:
console = Console(record=True)
# Render the table to a string
console.print(table_formatter(results))
else:
count = await search_index.count
agent_logger.info(f"No results found. Searched {count} docs")
count = await search_or_answers_index.count
agent_logger.info(f"No results found. Searched {count} docs.")

return results

0 comments on commit 5e01fa5

Please sign in to comment.