Skip to content

Commit 53b465d

Browse files
prakriti-solankeyvasanthasaikallurikartikpersistentabhishekkumar-27
committed
Global search fulltext (#767)
* added global search+vector+fulltext mode * added community details in chunk entities * added node ids * updated vector graph query * added entities and modified chat response * added params * api response changes * added chunk entity query * modifies query * payload changes * added nodetails properties * payload new changes * communities check * communities selecetion check * Communities bug solutions (#770) * added local chat history * added write access check * added write access param * labels cahnge for nodes * added fulltext creation * disabled the write and delete actions for read only user mode * modified query * test updates * test uupdated * enable communities * removed the selected prop * Read Only User Support (#766) * added local chat history * added write access check * added write access param * added fulltext creation * disabled the write and delete actions for read only user mode * modified query --------- Co-authored-by: vasanthasaikalluri <[email protected]> * storing the gds status and write access on refresh * enable communities label change --------- Co-authored-by: vasanthasaikalluri <[email protected]> Co-authored-by: kartikpersistent <[email protected]> Co-authored-by: abhishekkumar-27 <[email protected]> * readonly fixed on refresh * clear chat history * slectedFiles check for Chatbot * clear history --------- Co-authored-by: vasanthasaikalluri <[email protected]> Co-authored-by: kartikpersistent <[email protected]> Co-authored-by: abhishekkumar-27 <[email protected]>
1 parent 6fa5fb4 commit 53b465d

File tree

19 files changed

+664
-362
lines changed

19 files changed

+664
-362
lines changed

backend/score.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ async def post_processing(uri=Form(), userName=Form(), password=Form(), database
272272
json_obj = {'api_name': 'post_processing/create_entity_embedding', 'db_url': uri, 'logging_time': formatted_time(datetime.now(timezone.utc))}
273273
logger.log_struct(json_obj)
274274
logging.info(f'Entity Embeddings created')
275-
276-
if "create_communities" in tasks:
275+
276+
if "enable_communities" in tasks:
277277
model = "openai-gpt-4o"
278278
await asyncio.to_thread(create_communities, uri, userName, password, database,model)
279279
josn_obj = {'api_name': 'post_processing/create_communities', 'db_url': uri, 'logging_time': formatted_time(datetime.now(timezone.utc))}
@@ -321,10 +321,9 @@ async def chat_bot(uri=Form(),model=Form(None),userName=Form(), password=Form(),
321321
gc.collect()
322322

323323
@app.post("/chunk_entities")
324-
async def chunk_entities(uri=Form(),userName=Form(), password=Form(), database=Form(), chunk_ids=Form(None),is_entity=Form()):
324+
async def chunk_entities(uri=Form(),userName=Form(), password=Form(), database=Form(), nodedetails=Form(None),entities=Form(),mode=Form()):
325325
try:
326-
logging.info(f"URI: {uri}, Username: {userName}, chunk_ids: {chunk_ids}")
327-
result = await asyncio.to_thread(get_entities_from_chunkids,uri=uri, username=userName, password=password, database=database,chunk_ids=chunk_ids,is_entity=json.loads(is_entity.lower()))
326+
result = await asyncio.to_thread(get_entities_from_chunkids,uri=uri, username=userName, password=password, database=database,nodedetails=nodedetails,entities=entities,mode=mode)
328327
json_obj = {'api_name':'chunk_entities','db_url':uri, 'logging_time': formatted_time(datetime.now(timezone.utc))}
329328
logger.log_struct(json_obj)
330329
return create_api_response('Success',data=result)

backend/src/chunkid_entities.py

+60-44
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,16 @@ def process_chunk_data(chunk_data):
8181
except Exception as e:
8282
logging.error(f"chunkid_entities module: An error occurred while extracting the Chunk text from records: {e}")
8383

84-
def process_chunkids(driver, chunk_ids):
84+
def process_chunkids(driver, chunk_ids, entities):
8585
"""
8686
Processes chunk IDs to retrieve chunk data.
8787
"""
8888
try:
8989
logging.info(f"Starting graph query process for chunk ids: {chunk_ids}")
90-
chunk_ids_list = chunk_ids.split(",")
91-
92-
records, summary, keys = driver.execute_query(CHUNK_QUERY, chunksIds=chunk_ids_list)
90+
records, summary, keys = driver.execute_query(CHUNK_QUERY, chunksIds=chunk_ids,entityIds=entities["entityids"], relationshipIds=entities["relationshipids"])
9391
result = process_records(records)
92+
result["nodes"].extend(records[0]["nodes"])
93+
result["nodes"] = remove_duplicate_nodes(result["nodes"])
9494
logging.info(f"Nodes and relationships are processed")
9595

9696
result["chunk_data"] = process_chunk_data(records)
@@ -118,79 +118,95 @@ def remove_duplicate_nodes(nodes,property="element_id"):
118118

119119
return unique_nodes
120120

121-
def process_entityids(driver, chunk_ids):
121+
def process_entityids(driver, entity_ids):
122122
"""
123123
Processes entity IDs to retrieve local community data.
124124
"""
125125
try:
126-
logging.info(f"Starting graph query process for entity ids: {chunk_ids}")
127-
entity_ids_list = chunk_ids.split(",")
126+
logging.info(f"Starting graph query process for entity ids: {entity_ids}")
128127
query_body = LOCAL_COMMUNITY_SEARCH_QUERY.format(
129128
topChunks=LOCAL_COMMUNITY_TOP_CHUNKS,
130129
topCommunities=LOCAL_COMMUNITY_TOP_COMMUNITIES,
131130
topOutsideRels=LOCAL_COMMUNITY_TOP_OUTSIDE_RELS
132131
)
133132
query = LOCAL_COMMUNITY_DETAILS_QUERY_PREFIX + query_body + LOCAL_COMMUNITY_DETAILS_QUERY_SUFFIX
134133

135-
records, summary, keys = driver.execute_query(query, entityIds=entity_ids_list)
134+
records, summary, keys = driver.execute_query(query, entityIds=entity_ids)
136135

137136
result = process_records(records)
138137
if records:
139138
result["nodes"].extend(records[0]["nodes"])
140139
result["nodes"] = remove_duplicate_nodes(result["nodes"])
140+
141141
logging.info(f"Nodes and relationships are processed")
142+
142143
result["chunk_data"] = records[0]["chunks"]
143144
result["community_data"] = records[0]["communities"]
144145
else:
145146
result["chunk_data"] = list()
146147
result["community_data"] = list()
147-
logging.info(f"Query process completed successfully for chunk ids: {chunk_ids}")
148+
logging.info(f"Query process completed successfully for chunk ids: {entity_ids}")
148149
return result
149150
except Exception as e:
150-
logging.error(f"chunkid_entities module: Error processing entity ids: {chunk_ids}. Error: {e}")
151+
logging.error(f"chunkid_entities module: Error processing entity ids: {entity_ids}. Error: {e}")
151152
raise
152153

153-
def get_entities_from_chunkids(uri, username, password, database ,chunk_ids,is_entity=False):
154-
"""
155-
Retrieve and process nodes and relationships from a graph database given a list of chunk IDs.
154+
def process_communityids(driver, community_ids):
155+
"""Processes community IDs to retrieve community data."""
156+
try:
157+
logging.info(f"Starting graph query process for community ids: {community_ids}")
158+
query = GLOBAL_COMMUNITY_DETAILS_QUERY
159+
records, summary, keys = driver.execute_query(query, communityids=community_ids)
160+
161+
result = {"nodes": [], "relationships": [], "chunk_data": []}
162+
result["community_data"] = records[0]["communities"] if records else []
156163

157-
Parameters:
158-
uri (str): The URI of the graph database.
159-
username (str): The username for the database authentication.
160-
password (str): The password for the database authentication.
161-
chunk_ids (str): A comma-separated string of chunk IDs.
164+
logging.info(f"Query process completed successfully for community ids: {community_ids}")
165+
return result
166+
except Exception as e:
167+
logging.error(f"chunkid_entities module: Error processing community ids: {community_ids}. Error: {e}")
168+
raise
162169

163-
Returns:
164-
dict: A dictionary with 'nodes' and 'relationships' keys containing processed data, or an error message.
165-
"""
170+
def get_entities_from_chunkids(uri, username, password, database ,nodedetails,entities,mode):
166171
try:
167172

168173
driver = get_graphDB_driver(uri, username, password,database)
169-
if not is_entity:
170-
if chunk_ids:
171-
logging.info(f"chunkid_entities module: Starting for chunk ids : {chunk_ids}")
172-
result = process_chunkids(driver,chunk_ids)
174+
default_response = {"nodes": list(),"relationships": list(),"chunk_data": list(),"community_data": list(),}
175+
176+
nodedetails = json.loads(nodedetails)
177+
entities = json.loads(entities)
178+
179+
if mode == CHAT_GLOBAL_VECTOR_FULLTEXT_MODE:
180+
181+
if "communitydetails" in nodedetails and nodedetails["communitydetails"]:
182+
community_ids = [item["id"] for item in nodedetails["communitydetails"]]
183+
logging.info(f"chunkid_entities module: Starting for community ids: {community_ids}")
184+
return process_communityids(driver, community_ids)
185+
else:
186+
logging.info("chunkid_entities module: No community ids are passed")
187+
return default_response
188+
189+
elif mode == CHAT_ENTITY_VECTOR_MODE:
190+
191+
if "entitydetails" in nodedetails and nodedetails["entitydetails"]:
192+
entity_ids = [item["id"] for item in nodedetails["entitydetails"]]
193+
logging.info(f"chunkid_entities module: Starting for entity ids: {entity_ids}")
194+
return process_entityids(driver, entity_ids)
173195
else:
174-
logging.info(f"chunkid_entities module: No chunk ids are passed")
175-
result = {
176-
"nodes": [],
177-
"relationships": [],
178-
"chunk_data":[]
179-
}
180-
return result
181-
if chunk_ids:
182-
result = process_entityids(driver,chunk_ids)
183-
logging.info(f"chunkid_entities module: Starting for entity ids : {chunk_ids}")
196+
logging.info("chunkid_entities module: No entity ids are passed")
197+
return default_response
198+
184199
else:
185-
logging.info(f"chunkid_entities module: No entity ids are passed")
186-
result = {
187-
"nodes": [],
188-
"relationships": [],
189-
"chunk_data":[],
190-
"community_data":[]
191-
}
192-
return result
200+
201+
if "chunkdetails" in nodedetails and nodedetails["chunkdetails"]:
202+
chunk_ids = [item["id"] for item in nodedetails["chunkdetails"]]
203+
logging.info(f"chunkid_entities module: Starting for chunk ids: {chunk_ids}")
204+
return process_chunkids(driver, chunk_ids, entities)
205+
else:
206+
logging.info("chunkid_entities module: No chunk ids are passed")
207+
return default_response
193208

194209
except Exception as e:
195210
logging.error(f"chunkid_entities module: An error occurred in get_entities_from_chunkids. Error: {str(e)}")
196-
raise Exception(f"chunkid_entities module: An error occurred in get_entities_from_chunkids. Please check the logs for more details.") from e
211+
raise Exception(f"chunkid_entities module: An error occurred in get_entities_from_chunkids. Please check the logs for more details.") from e
212+

0 commit comments

Comments
 (0)