-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
654 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ dist/ | |
.coverage | ||
htmlcov/ | ||
.idea/ | ||
.env |
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,54 @@ | ||
from typing import List | ||
from neo4j import GraphDatabase | ||
from neo4j_genai import VectorRetriever | ||
|
||
from random import random | ||
from neo4j_genai.indexes import create_vector_index, drop_vector_index | ||
|
||
import os | ||
from langchain_openai import OpenAIEmbeddings | ||
|
||
URI = "neo4j://localhost:7687" | ||
AUTH = ("neo4j", "password") | ||
|
||
INDEX_NAME = "embedding-name-large" | ||
DIMENSION = 3072 | ||
|
||
# Connect to Neo4j database | ||
driver = GraphDatabase.driver(URI, auth=AUTH) | ||
|
||
|
||
# Create Embedder object | ||
embedder = OpenAIEmbeddings(model="text-embedding-3-large") | ||
|
||
# Initialize the retriever | ||
retriever = VectorRetriever(driver, embedder) | ||
|
||
drop_vector_index(driver, INDEX_NAME) | ||
|
||
# Creating the index | ||
create_vector_index( | ||
driver, | ||
INDEX_NAME, | ||
label="Document", | ||
property="propertyKey", | ||
dimensions=DIMENSION, | ||
similarity_fn="cosine", | ||
) | ||
|
||
# Upsert the query | ||
vector = [random() for _ in range(DIMENSION)] | ||
insert_query = ( | ||
"MERGE (n:Document)" | ||
"WITH n " | ||
"CALL db.create.setNodeVectorProperty(n, 'propertyKey', $vector)" | ||
"RETURN n" | ||
) | ||
parameters = { | ||
"vector": vector, | ||
} | ||
driver.execute_query(insert_query, parameters) | ||
|
||
# Perform the similarity search for a text query | ||
query_text = "hello world" | ||
print(retriever.search(INDEX_NAME, query_text=query_text, top_k=5)) |
Oops, something went wrong.