-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/add jina reranker rebased #312
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
cf24532
to
e8a612c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ Changes requested.
- Reviewed the entire pull request up to e8a612c
- Looked at
1684
lines of code in26
files - Took 7 minutes and 38 seconds to review
More info
- Skipped
1
files when reviewing. - Skipped posting
3
additional comments because they didn't meet confidence threshold of50%
.
1. r2r/core/pipelines/rag.py:85
:
- Assessed confidence :
100%
- Grade:
0%
- Comment:
The abstract methodrerank_results
should also include thelimit
parameter to match the implementation in the subclasses.
def rerank_results(
self, transformed_query: Any, results: list, limit: int
) -> list:
- Reasoning:
Thererank_results
function in theRAGPipeline
class has been updated to include alimit
parameter, but the abstract method in the base class has not been updated to reflect this change. This could lead to confusion or errors when implementing new subclasses ofRAGPipeline
.
2. r2r/pipelines/web/rag.py:53
:
- Assessed confidence :
80%
- Grade:
0%
- Comment:
Therun
function should check ifsearch_limit
andrerank_limit
are positive integers.
def run(
self,
query,
filters={},
search_limit=25,
rerank_limit=15,
search_only=False,
generation_config: Optional[GenerationConfig] = None,
*args,
**kwargs,
):
if not isinstance(search_limit, int) or search_limit <= 0:
raise ValueError("'search_limit' must be a positive integer")
if not isinstance(rerank_limit, int) or rerank_limit <= 0:
raise ValueError("'rerank_limit' must be a positive integer")
self.initialize_pipeline(query, False)
logger.debug(
f"Running the `WebRAGPipeline` with pipeline_run_info={self.pipeline_run_info}."
)
transformed_query = self.transform_query(query)
search_results = self.search(transformed_query, filters, limit)
context = self.construct_context(search_results)
prompt = self.construct_prompt({"query": query, "context": context})
if search_only:
return RAGPipelineOutput(search_results, None, None)
elif not generation_config:
return self.generate_completion(transformed_query, search_results)
else:
return self.generate_completion(
transformed_query, search_results, generation_config
)
- Reasoning:
Therun
function in theWebRAGPipeline
class has been updated to includesearch_limit
andrerank_limit
parameters, but the function does not check if these parameters are positive integers. This could lead to unexpected behavior or errors when the function is called with invalidsearch_limit
orrerank_limit
arguments.
3. r2r/pipelines/core/embedding.py:123
:
- Assessed confidence :
80%
- Grade:
0%
- Comment:
Therun
function should check ifsearch_limit
andrerank_limit
are positive integers.
def run(
self,
document: DocumentPage,
do_chunking=False,
do_upsert=True,
**kwargs: Any,
):
if not isinstance(search_limit, int) or search_limit <= 0:
raise ValueError("'search_limit' must be a positive integer")
if not isinstance(rerank_limit, int) or rerank_limit <= 0:
raise ValueError("'rerank_limit' must be a positive integer")
self.initialize_pipeline(document=document)
logger.debug(
f"Running the `BasicEmbeddingPipeline` with pipeline_run_info={self.pipeline_run_info}."
)
batch_data = []
chunks = (
self.chunk_text(document.text) if do_chunking else [document.text]
)
for chunk_iter, chunk in enumerate(chunks):
batch_data.append(
(
document.document_id,
document.page_number,
chunk_iter,
chunk,
copy.copy(document.metadata),
)
)
if len(batch_data) == self.embedding_batch_size:
self._process_batches(batch_data, do_upsert)
batch_data = []
# Process any remaining batch
if batch_data:
self._process_batches(batch_data, do_upsert)
- Reasoning:
Therun
function in theBasicEmbeddingPipeline
class has been updated to includesearch_limit
andrerank_limit
parameters, but the function does not check if these parameters are positive integers. This could lead to unexpected behavior or errors when the function is called with invalidsearch_limit
orrerank_limit
arguments.
Workflow ID: wflow_9lgHObXDBColvx9w
Want Ellipsis to fix these issues? Tag @ellipsis-dev
in a comment. We'll respond in a few minutes. Learn more here.
@@ -285,7 +290,8 @@ async def _stream_rag_completion( | |||
rag_pipeline.run( | |||
query.query, | |||
query.filters, | |||
query.limit, | |||
query.search_limit, | |||
query.renark_limit, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a typo in the parameter name. It should be rerank_limit
instead of renark_limit
.
query.renark_limit, | |
"rerank_limit": rerank_limit, |
), | ||
filters=filters, | ||
limit=limit, | ||
) | ||
return results | ||
|
||
def rerank_results( | ||
self, results: list[VectorSearchResult] | ||
self, transformed_query: str, results: list[VectorSearchResult], limit | ||
) -> list[VectorSearchResult]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rerank_results
function should check if limit
is a positive integer.
) -> list[VectorSearchResult]: | |
def rerank_results( | |
self, transformed_query: str, results: list[VectorSearchResult], limit: int | |
) -> list[VectorSearchResult]: | |
if not isinstance(limit, int) or limit <= 0: | |
raise ValueError("'limit' must be a positive integer") | |
return list(reversed(results))[0:limit] |
@@ -76,15 +76,17 @@ def add_entries( | |||
def search( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The search
function should check if search_limit
and rerank_limit
are positive integers.
def search( | |
def search( | |
self, | |
query: str, | |
search_limit: Optional[int] = 25, | |
rerank_limit: Optional[int] = 15, | |
filters: Optional[Dict[str, Any]] = None, | |
settings: Optional[Dict[str, Any]] = None, | |
): | |
if not isinstance(search_limit, int) or search_limit <= 0: | |
raise ValueError("'search_limit' must be a positive integer") | |
if not isinstance(rerank_limit, int) or rerank_limit <= 0: | |
raise ValueError("'rerank_limit' must be a positive integer") | |
json_data = { | |
"query": query, | |
"filters": filters or {}, | |
"search_limit": search_limit, | |
"rerank_limit": rerank_limit, | |
"settings": settings or {}, | |
} | |
response = requests.post(url, json=json_data) | |
return response.json() |
return self.llm.get_completion(messages, generation_config) | ||
return self.llm_provider.get_completion( | ||
messages, generation_config | ||
) | ||
|
||
return self._stream_generate_completion(messages, generation_config) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The run
function should check if search_limit
and rerank_limit
are positive integers.
def run( | |
self, | |
query, | |
filters={}, | |
search_limit=25, | |
rerank_limit=15, | |
search_only=False, | |
generation_config: Optional[GenerationConfig] = None, | |
*args, | |
**kwargs, | |
): | |
if not isinstance(search_limit, int) or search_limit <= 0: | |
raise ValueError("'search_limit' must be a positive integer") | |
if not isinstance(rerank_limit, int) or rerank_limit <= 0: | |
raise ValueError("'rerank_limit' must be a positive integer") | |
self.initialize_pipeline(query, search_only) | |
transformed_query = self.transform_query(query) | |
search_results = self.search(transformed_query, filters, search_limit) | |
search_results = self.rerank_results( | |
transformed_query, search_results, rerank_limit | |
) | |
if search_only: | |
return RAGPipelineOutput(search_results, None, None) | |
elif not generation_config: | |
return self.generate_completion(transformed_query, search_results) | |
else: | |
return self.generate_completion( | |
transformed_query, search_results, generation_config | |
) |
|
||
self.SentenceTransformer = SentenceTransformer | ||
# TODO - Modify this to be configurable, as `bge-reranker-large` is a `SentenceTransformer` model | ||
self.CrossEncoder = CrossEncoder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The get_embedding
function should check if stage
is an instance of PipelineStage
.
self.CrossEncoder = CrossEncoder | |
def get_embedding( | |
self, text: str, stage: PipelineStage = PipelineStage.SEARCH | |
) -> list[float]: | |
if not isinstance(stage, PipelineStage): | |
raise ValueError("'stage' must be an instance of `PipelineStage`") | |
if stage != PipelineStage.SEARCH: | |
raise ValueError("`get_embedding` only supports `SEARCH` stage.") | |
if not self.do_search: | |
raise ValueError( | |
"`get_embedding` can only be called for the search stage if a search model is set." | |
) | |
encoder = self.search_encoder | |
return encoder.encode([text]).tolist()[0] |
* Add jina reranker * fix oai
* Add jina reranker * fix oai
* Add jina reranker * fix oai
* Add jina reranker * fix oai
* update the default embd. (#310) * Feature/add jina reranker rebased (#312) * Add jina reranker * fix oai * Revampt client & server approach. (#316) * Revampt client & server approach. * cleanups * tweak hyde prompt * Feature/add agent provider (#317) * update pipeline (#315) * Update CONTRIBUTING.md * Delete CONTRIBUTOR.md * Adding agent provider * Feature/add agent provider rebased v2 (#319) * modify prompt provider workflow, add agent * fix run qna client * add provider abstraction * tweaks and cleans * move text splitter config locale * Feature/modify get all uniq values (#325) * refine * update * format * fix * Feature/dev merge rebased (#329) * Update local_rag.mdx * Update llms.mdx (#322) * update the default embd. (#310) * Feature/add agent provider (#317) * update pipeline (#315) * Update CONTRIBUTING.md * Delete CONTRIBUTOR.md * Adding agent provider * Feature/modify get all uniq values (#325) * refine * update * format * fix * dev merge * Feature/fix dev merge mistakes rebased (#330) * Feature/add agent provider (#317) * update pipeline (#315) * Update CONTRIBUTING.md * Delete CONTRIBUTOR.md * Adding agent provider * Feature/modify get all uniq values (#325) * refine * update * format * fix * dev merge * cleanup * Feature/dev cleanup (#331) * final pub * final pub * json clean * fix sentence transformer issue * include rerank * fix llama cpp * rebase * fix rerank * small tweaks * rollbk config * cleanup
* update the default embd. (SciPhi-AI#310) * Feature/add jina reranker rebased (SciPhi-AI#312) * Add jina reranker * fix oai * Revampt client & server approach. (SciPhi-AI#316) * Revampt client & server approach. * cleanups * tweak hyde prompt * Feature/add agent provider (SciPhi-AI#317) * update pipeline (SciPhi-AI#315) * Update CONTRIBUTING.md * Delete CONTRIBUTOR.md * Adding agent provider * Feature/add agent provider rebased v2 (SciPhi-AI#319) * modify prompt provider workflow, add agent * fix run qna client * add provider abstraction * tweaks and cleans * move text splitter config locale * Feature/modify get all uniq values (SciPhi-AI#325) * refine * update * format * fix * Feature/dev merge rebased (SciPhi-AI#329) * Update local_rag.mdx * Update llms.mdx (SciPhi-AI#322) * update the default embd. (SciPhi-AI#310) * Feature/add agent provider (SciPhi-AI#317) * update pipeline (SciPhi-AI#315) * Update CONTRIBUTING.md * Delete CONTRIBUTOR.md * Adding agent provider * Feature/modify get all uniq values (SciPhi-AI#325) * refine * update * format * fix * dev merge * Feature/fix dev merge mistakes rebased (SciPhi-AI#330) * Feature/add agent provider (SciPhi-AI#317) * update pipeline (SciPhi-AI#315) * Update CONTRIBUTING.md * Delete CONTRIBUTOR.md * Adding agent provider * Feature/modify get all uniq values (SciPhi-AI#325) * refine * update * format * fix * dev merge * cleanup * Feature/dev cleanup (SciPhi-AI#331) * final pub * final pub * json clean * fix sentence transformer issue * include rerank * fix llama cpp * rebase * fix rerank * small tweaks * rollbk config * cleanup
Summary:
This PR introduces a reranking feature to the R2R project, modifies various parameters related to search and reranking, updates configuration files, and modifies several classes to support the new reranking feature.
Key points:
SentenceTransformerEmbeddingProvider
class to support separate models for search and reranking.QnARAGPipeline
andWebRAGPipeline
classes to support the new reranking feature.Generated with ❤️ by ellipsis.dev