forked from neo4j/neo4j-graphrag-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Qdrant external retriever (neo4j#154)
* feat: Qdrant external retriever * test: ci updates * chore: add qdrant-client to dev deps * chore: poetry.lock * Update docs/source/api.rst Co-authored-by: willtai <[email protected]> * chore: fix mypy nit * Update docs/source/user_guide_rag.rst Co-authored-by: willtai <[email protected]> --------- Co-authored-by: willtai <[email protected]> Co-authored-by: willtai <[email protected]>
- Loading branch information
1 parent
6a8cea6
commit eeedf49
Showing
21 changed files
with
996 additions
and
39 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
### Start services locally | ||
|
||
Run the following command to spin up Neo4j and Qdrant containers. | ||
|
||
```bash | ||
docker compose -f tests/e2e/docker-compose.yml up | ||
``` | ||
|
||
### Write data (once) | ||
|
||
Run this from the project root to write data to both Neo4J and Qdrant. | ||
|
||
```bash | ||
poetry run python tests/e2e/qdrant_e2e/populate_dbs.py | ||
``` | ||
|
||
### Install Qdrant client | ||
|
||
```bash | ||
pip install qdrant-client | ||
``` | ||
|
||
### Search | ||
|
||
```bash | ||
# search by vector | ||
poetry run python -m examples.qdrant.vector_search | ||
|
||
# search by text, with embeddings generated locally | ||
poetry run python -m examples.qdrant.text_search | ||
``` |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from langchain_huggingface.embeddings import HuggingFaceEmbeddings | ||
from neo4j import GraphDatabase | ||
from neo4j_graphrag.retrievers import QdrantNeo4jRetriever | ||
from qdrant_client import QdrantClient | ||
|
||
NEO4J_URL = "neo4j://localhost:7687" | ||
NEO4J_AUTH = ("neo4j", "password") | ||
|
||
|
||
def main() -> None: | ||
with GraphDatabase.driver(NEO4J_URL, auth=NEO4J_AUTH) as neo4j_driver: | ||
embedder = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2") | ||
retriever = QdrantNeo4jRetriever( | ||
driver=neo4j_driver, | ||
client=QdrantClient(url="http://localhost:6333"), | ||
collection_name="Jeopardy", | ||
id_property_external="neo4j_id", | ||
id_property_neo4j="id", | ||
embedder=embedder, # type: ignore | ||
) | ||
|
||
res = retriever.search(query_text="biology", top_k=2) | ||
print(res) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from neo4j import GraphDatabase | ||
from neo4j_graphrag.retrievers import QdrantNeo4jRetriever | ||
from qdrant_client import QdrantClient | ||
|
||
from examples.embedding_biology import EMBEDDING_BIOLOGY | ||
|
||
NEO4J_URL = "neo4j://localhost:7687" | ||
NEO4J_AUTH = ("neo4j", "password") | ||
|
||
|
||
def main() -> None: | ||
with GraphDatabase.driver(NEO4J_URL, auth=NEO4J_AUTH) as neo4j_driver: | ||
retriever = QdrantNeo4jRetriever( | ||
driver=neo4j_driver, | ||
client=QdrantClient(url="http://localhost:6333"), | ||
collection_name="Jeopardy", | ||
id_property_external="neo4j_id", | ||
id_property_neo4j="id", | ||
) | ||
res = retriever.search(query_vector=EMBEDDING_BIOLOGY, top_k=2) | ||
print(res) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.