참고소스 수정본

This commit is contained in:
LASTA_DEV01\lasta
2026-05-12 19:40:31 +09:00
parent 0f34a451fc
commit 2e9204243d
8708 changed files with 3259488 additions and 869 deletions

View File

@@ -0,0 +1,30 @@
### Usage Instructions
You will need both a Pinecone vector database and a Neo4j database to use this retriever.
### Writing Test Data
Update `NEO4J_AUTH`, `NEO4J_URL`, and `PC_API_KEY` variables in the `tests/e2e/pinecone_e2e/populate_dbs.py` script then run this from the project root to write test data to both dbs.
```
uv run python -m tests/e2e/pinecone_e2e/populate_dbs.py
```
### Install Pinecone client
You need to install the `pinecone-client` package to use this retriever.
```bash
pip install pinecone-client
```
### Search
Update the `NEO4J_AUTH`, `NEO4J_URL`, and `PC_API_KEY` variables in each file then run one of the following from the project root to test the retriever.
```
# Search by vector
uv run python -m examples.customize.retrievers.external.pinecone.vector_search
# Search by text, with embeddings generated locally
uv run python -m examples.customize.retrievers.external.pinecone.text_search
```

View File

@@ -0,0 +1,40 @@
"""This example demonstrates how to use PineconeNeo4jRetriever, ie vectors are
stored in the Pinecone database.
See the [README](./README.md) for more
information about how spin up a Pinecone and Neo4j databases if needed.
In this example, search is performed from a text. Embeddings are computed
using OpenAI models. See [../../embeddings/](../../embeddings/) for examples
using other supported embedders.
"""
from neo4j import GraphDatabase
from neo4j_graphrag.embeddings import OpenAIEmbeddings
from neo4j_graphrag.retrievers import PineconeNeo4jRetriever
from pinecone import Pinecone
NEO4J_AUTH = ("neo4j", "password")
NEO4J_URL = "neo4j://localhost:7687"
PC_API_KEY = "API_KEY"
def main() -> None:
with GraphDatabase.driver(NEO4J_URL, auth=NEO4J_AUTH) as neo4j_driver:
pc_client = Pinecone(PC_API_KEY)
embedder = OpenAIEmbeddings()
retriever = PineconeNeo4jRetriever(
driver=neo4j_driver,
client=pc_client,
index_name="jeopardy",
id_property_neo4j="id",
embedder=embedder,
)
res = retriever.search(query_text="biology", top_k=2)
print(res)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,39 @@
"""This example demonstrates how to use PineconeNeo4jRetriever, ie vectors are
stored in the Pinecone database.
See the [README](./README.md) for more
information about how spin up a Pinecone and Neo4j databases if needed.
In this example, search is performed from an already computed vector.
"""
from neo4j import GraphDatabase
from neo4j_graphrag.embeddings.sentence_transformers import (
SentenceTransformerEmbeddings,
)
from neo4j_graphrag.retrievers import PineconeNeo4jRetriever
from pinecone import Pinecone
NEO4J_AUTH = ("neo4j", "password")
NEO4J_URL = "neo4j://localhost:7687"
PC_API_KEY = "API_KEY"
def main() -> None:
with GraphDatabase.driver(NEO4J_URL, auth=NEO4J_AUTH) as neo4j_driver:
pc_client = Pinecone(PC_API_KEY)
embedder = SentenceTransformerEmbeddings(model="all-MiniLM-L6-v2")
retriever = PineconeNeo4jRetriever(
driver=neo4j_driver,
client=pc_client,
index_name="jeopardy",
id_property_neo4j="id",
embedder=embedder,
)
res = retriever.search(query_text="biology", top_k=2)
print(res)
if __name__ == "__main__":
main()