Skip to content

Commit 013e76a

Browse files
updated the source list api
1 parent 9220776 commit 013e76a

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

backend/score.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ async def extract_knowledge_graph_from_file(
129129

130130

131131
@app.get("/sources_list")
132-
async def get_source_list():
132+
async def get_source_list(uri=Form(),userName=Form(),password=Form()):
133133
"""
134134
Calls 'get_source_list_from_graph' which returns list of sources which alreday exist in databse
135135
"""
136-
result = await asyncio.to_thread(get_source_list_from_graph)
136+
result = await asyncio.to_thread(get_source_list_from_graph,uri,userName,password)
137137
return result
138138

139139
@app.post("/update_similarity_graph")

backend/src/main.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ def extract_graph_from_file(uri, userName, password, model, file=None,source_url
308308
graph_documents = extract_graph_from_OpenAI(model_version,graph,chunks,file_name,uri,userName,password)
309309

310310
#update_similarity_graph for the KNN Graph
311-
update_graph()
311+
update_graph(graph)
312312

313313
distinct_nodes = set()
314314
relations = []
@@ -393,14 +393,21 @@ def get_documents_from_youtube(url):
393393
print("Youtube pages = ",pages)
394394
return file_name, file_key, pages
395395

396-
def get_source_list_from_graph():
396+
def get_source_list_from_graph(uri,userName,password):
397397
"""
398+
Args:
399+
uri: URI of the graph to extract
400+
userName: Username to use for graph creation ( if None will use username from config file )
401+
password: Password to use for graph creation ( if None will use password from config file )
402+
file: File object containing the PDF file to be used
403+
model: Type of model to use ('Diffbot'or'OpenAI GPT')
404+
Returns:
398405
Returns a list of sources that are in the database by querying the graph and
399406
sorting the list by the last updated date.
400407
"""
401408
logging.info("Get existing files list from graph")
402409
try:
403-
graph = Neo4jGraph()
410+
graph = Neo4jGraph(url=uri, username=userName, password=password)
404411
query = "MATCH(d:Document) RETURN d ORDER BY d.updatedAt DESC"
405412
result = graph.query(query)
406413
list_of_json_objects = [entry['d'] for entry in result]
@@ -411,14 +418,14 @@ def get_source_list_from_graph():
411418
logging.exception('Exception')
412419
return create_api_response(job_status,error=error_message)
413420

414-
def update_graph():
421+
def update_graph(graph):
415422
"""
416423
Update the graph node with SIMILAR relationship where embedding scrore match
417424
"""
418425
knn_min_score = os.environ.get('KNN_MIN_SCORE')
419426

420427
query = "WHERE node <> c and score >= {} MERGE (c)-[rel:SIMILAR]-(node) SET rel.score = score"
421-
graph = Neo4jGraph()
428+
# graph = Neo4jGraph()
422429
result = graph.query("""MATCH (c:Chunk)
423430
WHERE c.embedding IS NOT NULL AND count { (c)-[:SIMILAR]-() } < 5
424431
CALL db.index.vector.queryNodes('vector', 6, c.embedding) yield node, score """+ query.format(knn_min_score))

0 commit comments

Comments
 (0)