Repository navigation
Conversation
| } | ||
| questions = self.llm_response_forget(prompt).content | ||
| return Document( | ||
| content=questions, |
There was a problem hiding this comment.
The content is just the questions, which is fine since it helps match the query, but we lose the original content. I know you are keeping it in the metadata, but original_content is not used in the normal flow of this agent anywhere.
I think it's better to augment the content field value with the questions, and also demarcate those questions in some special way, so that during passage retrieval, the questions are ignored. I.e. only use the questions for matching/ranking, but ignore in retrieval.
There was a problem hiding this comment.
The other advantage of augmenting (i.e. combining chunk content + questions) is that now we can match with both the question and content, rather than having to deal with de-duplication, e.g. when we find a match for questions_5 that links to chunk_3 and also find a match to chunk_3.
There was a problem hiding this comment.
Thanks for the feedback!
I've implemented the suggested improvements like this:
-
Combined content+questions in a single field instead of separating them, using a consistent marker (
GENERATED_QUESTIONS_MARKER) to demarcate them. -
Added
clean_generated_content()method in the so that questions are used in ranking but not showed in retrieval
There was a problem hiding this comment.
Thank you @dfm88 ! Added to my queue of things to look at this week.
|
Thanks for this @dfm88 |
73b2978 to
9c385f0
Compare
b1d7f78 to
7282d26
Compare
7282d26 to
350175b
Compare
There was a problem hiding this comment.
Here I had to change the signature of
llm_response_forget and llm_response_forget_async (which might also have sense) because I had MyPy problem in passing the llm_response_forget_async method to run_batch_agent_method
|
|
||
| return query, extracts | ||
|
|
||
| def clean_generated_content(self, passages: List[Document]) -> List[Document]: |
There was a problem hiding this comment.
suggest rename - remove_hypothetical_questions to be more clear
There was a problem hiding this comment.
I thoughy it might need for other cleaning stuff so I used a generic name, but ok I'll make it specific for this task
| @pytest.mark.parametrize( | ||
| "hypothetical_questions, expect_cleaned", [(True, True), (False, False)] | ||
| ) | ||
| def test_clean_generated_content( |
There was a problem hiding this comment.
==> test_remove_generated_questions
pchalasani
left a comment
There was a problem hiding this comment.
Thanks @dfm88 I just reviewed it.
|
Hi @pchalasani , sorry for the delay in making changes on this. Here an overview of the changes, since it was not a straightforward task to handle batch number: I saw you added a function in The most challenging part was ensuring correct behavior when stop_on_first_result=True, so I maintained strict task ordering by preserving original indices. For normal operation (when stop_on_first_result=False), the code fully leverages the batching capabilities. I have also added an example of when leveraging Hypothetical Questions might be beneficial. Here another interesting article Advanced RAG Optimization: Aligning Question and Document Embedding Spaces with Hypothetical Questions I know there are a lot of changes, but tests using batch module are passing. Let me know if you'd like me to clarify any part of these changes or have suggestions for improvement. |
|
Thank you @dfm88 will check in a few days. |
|
|
||
| async def _do_task(input: str | ChatDocument, i: int) -> Any: | ||
| agent_cfg.name = f"{agent_cfg.name}-{i}" | ||
| first_result = None |
There was a problem hiding this comment.
Thanks for this @dfm88.
Is there a reason the implementation of stop_on_first_result here is different from the one in run_batch_task_gen -- is this somehow better? This will help me better understand + review.
There was a problem hiding this comment.
Hi @pchalasani,
thank you for pointing this out. I actually didn't notice the run_batch_task_gen implementation when I was working on this PR. Looking at it now, I can see it already provides a good handling of batch async tasks, so I basically took inspiration from that to implement batch_size also in run_batch_agent_method in my last commit.
So I could revert also the changes I did to langroid/agent/batch.py::run_batch_function.
Finally I fixed the tests where I still was using the previous naming for the doc agent method relative to hypothetical questions.
There was a problem hiding this comment.
Will review soon thanks !
| f"{agent_name}{complete_str}..." | ||
| ) | ||
|
|
||
| if stop_on_first_result and any(results): |
There was a problem hiding this comment.
I think we should discard None results here, just like we do in the run_batch_task_gen fn.
Also more generally, since this _do_all functions in the two places are so similar, I think we should avoid code duplication and have a common fn and use it in both places. What do you think @dfm88 ?
fc2931f to
4150509
Compare
|
@dfm88 this is going to be very useful, as you say in cases with very technical/domain-specific terms that are not captured well by generic embeddings. I changed your example script to the medical domain to illustrate the benefit more clearly and explicitly, see the I added explanatory notes at the top of the script. EDIT - Please merge the changes from branch |
Great thanks! I did the merge |
|
@dfm88 I am making some changes on top of this. |
Yeah I see, it makes a lot of sense to me, thanks! |
Thank you for leading this PR ! |
|
finished in #683 |
Hypothetical Question Index
Despite there being no papers supporting this technique, Hypothetical Question Indexing is mentioned in several blogs as an advanced RAG technique. It somewhat contrasts with Hypothetical Answer (HyDE) and intervenes during the embedding saving phase, specifically trying to solve the problem where the question posed on an embedding contains words distant from it. Therefore, it associates different questions to increase the probability of retrieval.
Some link: