feat(retrievers): add async retriever support via neo4j.AsyncDriver (#406)#552
Open
1HazyOne707 wants to merge 1 commit into
Open
feat(retrievers): add async retriever support via neo4j.AsyncDriver (#406)#5521HazyOne707 wants to merge 1 commit into
1HazyOne707 wants to merge 1 commit into
Conversation
…eo4j#406) Adds AsyncRetriever base class and async variants of all core retrievers, allowing users to use neo4j.AsyncDriver without maintaining two driver instances or spawning threads. Changes: - types.py: Add AsyncNeo4jDriverModel (validates neo4j.AsyncDriver) and async model variants for all retrievers - retrievers/base.py: Add AsyncRetriever ABC with async search(), async get_search_results(), async _fetch_index_infos() - retrievers/async_vector.py: AsyncVectorRetriever, AsyncVectorCypherRetriever - retrievers/async_hybrid.py: AsyncHybridRetriever, AsyncHybridCypherRetriever - retrievers/async_text2cypher.py: AsyncText2CypherRetriever - retrievers/__init__.py: Export all async retriever classes Usage: driver = neo4j.AsyncGraphDatabase.driver(URI, auth=AUTH) retriever = await AsyncVectorRetriever(driver, 'my-index').async_init() results = await retriever.search(query_text='find something', top_k=5) Closes neo4j#406
Author
|
Hi @stellasia — I've opened this PR to address #406. I also submitted the Neo4j CLA to cla@neo4j.com earlier today, so that should be processing. Happy to make any adjustments based on your feedback — particularly around the |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Closes #406
Adds async variants of all core retrievers so users can use
neo4j.AsyncDriverwithout maintaining two driver instances in parallel or spawning threads to avoid blocking the event loop.Usage
Design
async_init()is a separate awaitable method (since__init__cannot be async) that fetches index metadata from Neo4j — mirrors the sync retriever pattern where_fetch_index_infos()is called in__init__driver.execute_query()calls are replaced withawait driver.execute_query()AsyncText2CypherRetriever.async_init()fetches the Neo4j schema if not provided at construction timeChanges
src/neo4j_graphrag/types.pyAsyncNeo4jDriverModel— validatesneo4j.AsyncDriverAsyncVectorRetrieverModel,AsyncVectorCypherRetrieverModel,AsyncHybridRetrieverModel,AsyncHybridCypherRetrieverModel,AsyncText2CypherRetrieverModelsrc/neo4j_graphrag/retrievers/base.pyAsyncRetrieverABC withasync search(),async get_search_results(),async _fetch_index_infos()New files
retrievers/async_vector.py—AsyncVectorRetriever,AsyncVectorCypherRetrieverretrievers/async_hybrid.py—AsyncHybridRetriever,AsyncHybridCypherRetrieverretrievers/async_text2cypher.py—AsyncText2CypherRetrieverretrievers/__init__.pytests/unit/retrievers/test_async_vector.py