Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update graph search tracing method #241

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions backend/app/rag/knowledge_graph/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,35 +299,35 @@ def process_query(sub_query):
Scoped_Session.remove()
return sub_query, entities, relationships

with concurrent.futures.ThreadPoolExecutor() as executor:
future_to_query = {
executor.submit(process_query, sub_query): sub_query
for sub_query in semantic_queries
}
for future in concurrent.futures.as_completed(future_to_query):
sub_query = future_to_query[future]
try:
# It can't record the real execution time of the sub_query
with self._callback_manager.as_trace("intent_based_search"):
with self._callback_manager.event(
MyCBEventType.GRAPH_SEMANTIC_SEARCH,
payload={EventPayload.QUERY_STR: sub_query},
) as event:
sub_query, entities, relationships = future.result()
event.on_end(
payload={
"entities": entities,
"relationships": relationships,
},
)
result["queries"][sub_query] = {
"entities": entities,
"relationships": relationships,
with self._callback_manager.as_trace("intent_based_search"):
with self._callback_manager.event(
MyCBEventType.GRAPH_SEMANTIC_SEARCH,
payload={EventPayload.QUERY_STR: semantic_queries},
) as event:
with concurrent.futures.ThreadPoolExecutor() as executor:
future_to_query = {
executor.submit(process_query, sub_query): sub_query
for sub_query in semantic_queries
}
all_entities.extend(entities)
add_relationships(relationships)
except Exception as exc:
logger.error(f"{sub_query} generated an exception: {exc}")
for future in concurrent.futures.as_completed(future_to_query):
sub_query = future_to_query[future]
try:
# It can't record the real execution time of the sub_query
sub_query, entities, relationships = future.result()
result["queries"][sub_query] = {
"entities": entities,
"relationships": relationships,
}
all_entities.extend(entities)
add_relationships(relationships)
except Exception as exc:
logger.error(f"{sub_query} generated an exception: {exc}")

event.on_end(
payload={
"queries": result["queries"],
},
)

unique_entities = {e["id"]: e for e in all_entities}.values()

Expand Down