Skip to content

Commit 5b19d9e

Browse files
Update KNN graph
1 parent 863c11d commit 5b19d9e

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

backend/score.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,15 @@ async def get_source_list(uri:str,
144144
return result
145145

146146
@app.post("/update_similarity_graph")
147-
async def update_similarity_graph():
147+
async def update_similarity_graph(uri=Form(None),
148+
userName=Form(None),
149+
password=Form(None),
150+
database=Form(None)):
148151
"""
149152
Calls 'update_graph' which post the query to update the similiar nodes in the graph
150153
"""
151154

152-
result = await asyncio.to_thread(update_graph)
155+
result = await asyncio.to_thread(update_graph,uri,userName,password,database)
153156
return result
154157

155158
def decode_password(pwd):

backend/src/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,15 +499,15 @@ def get_source_list_from_graph(uri,userName,password,db_name=None):
499499
logging.exception(f'Exception:{error_message}')
500500
return create_api_response(job_status,message=message,error=error_message)
501501

502-
def update_graph(graph):
502+
def update_graph(uri,userName,password,db_name):
503503
"""
504504
Update the graph node with SIMILAR relationship where embedding scrore match
505505
"""
506506
try:
507507
knn_min_score = os.environ.get('KNN_MIN_SCORE')
508508

509509
query = "WHERE node <> c and score >= {} MERGE (c)-[rel:SIMILAR]-(node) SET rel.score = score"
510-
# graph = Neo4jGraph()
510+
graph = Neo4jGraph(url=uri, database=db_name, username=userName, password=password)
511511
result = graph.query("""MATCH (c:Chunk)
512512
WHERE c.embedding IS NOT NULL AND count { (c)-[:SIMILAR]-() } < 5
513513
CALL db.index.vector.queryNodes('vector', 6, c.embedding) yield node, score """+ query.format(knn_min_score))

0 commit comments

Comments
 (0)