Skip to content

updated graph query #590

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

Merged
merged 1 commit into from
Jul 19, 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
16 changes: 6 additions & 10 deletions backend/src/shared/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@



##graph viz


GRAPH_CHUNK_LIMIT = 50
GRAPH_CHUNK_LIMIT = 50

#query
GRAPH_QUERY = """
Expand All @@ -34,8 +31,8 @@
RETURN c, chunks LIMIT {graph_chunk_limit}
}}

WITH collect([docs, chunks]) as data, collect(distinct c) as selectedChunks
WITH data, selectedChunks
WITH collect(distinct docs) as docs, collect(distinct chunks) as chunks, collect(distinct c) as selectedChunks
WITH docs, chunks, selectedChunks
// select relationships between selected chunks
WITH *,
[ c in selectedChunks | [p=(c)-[:NEXT_CHUNK|SIMILAR]-(other) WHERE other IN selectedChunks | p]] as chunkRels
Expand All @@ -52,16 +49,15 @@
RETURN collect(entities) as entities, collect(entityRels) as entityRels
}}

WITH apoc.coll.flatten(data + chunkRels + entities + entityRels, true) as paths
WITH apoc.coll.flatten(docs + chunks + chunkRels + entities + entityRels, true) as paths

// distinct nodes and rels
CALL {{ WITH paths UNWIND paths AS path UNWIND nodes(path) as node WITH distinct node
RETURN collect(node /* {{.*, labels:labels(node), elementId:elementId(node), embedding:null, text:null}} */)
AS nodes }}
RETURN collect(node /* {{.*, labels:labels(node), elementId:elementId(node), embedding:null, text:null}} */) AS nodes }}
CALL {{ WITH paths UNWIND paths AS path UNWIND relationships(path) as rel RETURN collect(distinct rel) AS rels }}
RETURN nodes, rels
"""

"""

## CHAT SETUP
CHAT_MAX_TOKENS = 1000
Expand Down