-
Notifications
You must be signed in to change notification settings - Fork 16.3k
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
langchain: Use map() and avoid "ValueError: max() arg is an empty sequence" in MergerRetriever #18679
Merged
baskaryan
merged 5 commits into
langchain-ai:master
from
n1lanjan:update-merger-retriever
Mar 28, 2024
Merged
langchain: Use map() and avoid "ValueError: max() arg is an empty sequence" in MergerRetriever #18679
baskaryan
merged 5 commits into
langchain-ai:master
from
n1lanjan:update-merger-retriever
Mar 28, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Adding a default 0 for cases when retriever_docs is empty list to avoid "ValueError: max() arg is an empty sequence"
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
baskaryan
approved these changes
Mar 28, 2024
gkorland
pushed a commit
to FalkorDB/langchain
that referenced
this pull request
Mar 30, 2024
…pty sequence" in MergerRetriever (langchain-ai#18679) - **Issue:** When passing an empty list to MergerRetriever it fails with error: ValueError: max() arg is an empty sequence - **Description:** We have a use case where we dynamically select retrievers and use MergerRetriever for merging the output of the retrievers. We faced this issue when the retriever_docs list is empty. Adding a default 0 for cases when retriever_docs is an empty list to avoid "ValueError: max() arg is an empty sequence". Also, changed to use map() which is more than twice as fast compared to the current implementation. ``` import timeit # Sample retriever_docs with varying lengths of sublists retriever_docs = [[i for i in range(j)] for j in range(1, 1000)] # First code snippet code1 = ''' max_docs = max(len(docs) for docs in retriever_docs) ''' # Second code snippet code2 = ''' max_docs = max(map(len, retriever_docs), default=0) ''' # Benchmarking time1 = timeit.timeit(stmt=code1, globals=globals(), number=10000) time2 = timeit.timeit(stmt=code2, globals=globals(), number=10000) # Output print(f"Execution time for code snippet 1: {time1} seconds") print(f"Execution time for code snippet 2: {time2} seconds") ``` - **Dependencies:** none
hinthornw
pushed a commit
that referenced
this pull request
Apr 26, 2024
…pty sequence" in MergerRetriever (#18679) - **Issue:** When passing an empty list to MergerRetriever it fails with error: ValueError: max() arg is an empty sequence - **Description:** We have a use case where we dynamically select retrievers and use MergerRetriever for merging the output of the retrievers. We faced this issue when the retriever_docs list is empty. Adding a default 0 for cases when retriever_docs is an empty list to avoid "ValueError: max() arg is an empty sequence". Also, changed to use map() which is more than twice as fast compared to the current implementation. ``` import timeit # Sample retriever_docs with varying lengths of sublists retriever_docs = [[i for i in range(j)] for j in range(1, 1000)] # First code snippet code1 = ''' max_docs = max(len(docs) for docs in retriever_docs) ''' # Second code snippet code2 = ''' max_docs = max(map(len, retriever_docs), default=0) ''' # Benchmarking time1 = timeit.timeit(stmt=code1, globals=globals(), number=10000) time2 = timeit.timeit(stmt=code2, globals=globals(), number=10000) # Output print(f"Execution time for code snippet 1: {time1} seconds") print(f"Execution time for code snippet 2: {time2} seconds") ``` - **Dependencies:** none
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
🤖:bug
Related to a bug, vulnerability, unexpected error with an existing feature
lgtm
PR looks good. Use to confirm that a PR is ready for merging.
Ɑ: retriever
Related to retriever module
size:XS
This PR changes 0-9 lines, ignoring generated files.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue: When passing an empty list to MergerRetriever it fails with error: ValueError: max() arg is an empty sequence
Description: We have a use case where we dynamically select retrievers and use MergerRetriever for merging the output of the retrievers. We faced this issue when the retriever_docs list is empty. Adding a default 0 for cases when retriever_docs is an empty list to avoid "ValueError: max() arg is an empty sequence". Also, changed to use map() which is more than twice as fast compared to the current implementation.