### Basic GraphRAG Retrieval Query Example (Python) Source: https://graphrag.com/concepts/intro-to-graphrag This Python snippet demonstrates a basic retrieval query for GraphRAG using the Neo4j vector integration. It defines a query to return the 'name' and 'score' of a node along with its 'metadata' (URL), and then uses this query with an existing Neo4j index to perform a similarity search for 'Jon Snow'. ```python retrieval_query = """ RETURN "Name: " + node.name AS text, score, {source:node.url} AS metadata """ retrieval_example = Neo4jVector.from_existing_index( OpenAIEmbeddings(), url=url, username=username, password=password, index_name="person_index", retrieval_query=retrieval_query, ) retrieval_example.similarity_search("Jon Snow", k=1) ``` -------------------------------- ### Get Movies Released Within a Year Range Source: https://graphrag.com/reference/graphrag/dynamic-cypher-generation This Cypher query fetches movies released between a given start year and end year. It accepts two parameters: $startYear and $endYear. This is useful for filtering movie results based on their release date. ```cypher // Which movies were released between $startYear and $endYear MATCH (m:Movie) WHERE $startYear <= m.year <= $endYear RETURN m.title, m.year ``` -------------------------------- ### Get Movies Directed by a Specific Director Source: https://graphrag.com/reference/graphrag/dynamic-cypher-generation This Cypher query retrieves the titles and release years of movies directed by a specified director. It takes the director's name as a parameter ($director). This snippet is useful for answering questions about a director's filmography. ```cypher // Which movies has ($director) directed? MATCH (d:Director)-[:DIRECTED]->(m:Movie) WHERE d.name = $director RETURN m.title, m.year ``` -------------------------------- ### GraphRAG Retrieval Query - Cypher Source: https://graphrag.com/reference/graphrag/graph-enhanced-vector-search This Cypher query demonstrates a retrieval process within a GraphRAG pattern. It starts by matching nodes connected to documents, then performs a graph traversal to find related entities and paths up to a certain depth. This helps in retrieving richer context beyond simple vector similarity. ```cypher MATCH (node)-[:PART_OF]->(d:Document) CALL { WITH node MATCH (node)-[:HAS_ENTITY]->(e) MATCH path=(e)(()-[rels:!HAS_ENTITY&!PART_OF]-()){0,2}(:!Chunk&!Document) ... RETURN ... } RETURN ... ``` -------------------------------- ### Retrieve Community Summaries by Level (Cypher) Source: https://graphrag.com/reference/graphrag/global-community-summary-retriever This Cypher query retrieves all 'full_content' from nodes labeled as '__Community__' that match a specified 'level'. It's used in the default implementation of the Global Community Summary Retriever to fetch all community summaries for a given level without vector search. ```cypher MATCH (c:__Community__) WHERE c.level = $level RETURN c.full_content AS output ``` -------------------------------- ### Define NEXT Relationship in Graph Pattern Source: https://graphrag.com/reference/knowledge-graph/text-seq Defines the 'NEXT' relationship in a graph pattern, used to link sequential 'Text' nodes. This relationship forms a linked list structure, indicating the order of texts within the sequence. ```Cypher (1)=[:NEXT]=> (1) ``` -------------------------------- ### Cypher Query for Hypothetical Question Retriever Source: https://graphrag.com/reference/graphrag/hypothetical-question-retriever This Cypher query retrieves chunks based on their relationship to hypothetical questions. It finds nodes connected to chunks via a HAS_QUESTION relationship, selects the chunk with the maximum score (deduplicating chunks if multiple questions relate to the same chunk), and returns the chunk's text, score, and metadata. ```cypher MATCH (node)<-[:HAS_QUESTION]-(chunk) WITH chunk, max(score) AS score // deduplicate chunks RETURN chunk.text AS text, score, {} AS metadata ``` -------------------------------- ### Define Text Node Structure in Graph Pattern Source: https://graphrag.com/reference/knowledge-graph/text-seq Defines the structure of a 'Text' node in a graph pattern. This node stores the original source text, its embedding as a float array, and optionally a source reference. It forms the basis for lexical graph patterns. ```Cypher (:Text { text::string, textEmbedding::float[], source::string? } ) ``` -------------------------------- ### Cypher Query for Parent-Child Retrieval Source: https://graphrag.com/reference/graphrag/parent-child-retriever This Cypher query retrieves parent nodes and their associated child chunks based on similarity scores. It aggregates child texts and returns the parent's title, combined child texts, score, and metadata (URL). This is used in the retrieval process to fetch relevant context for answer generation. ```cypher MATCH (node)<-[:HAS_CHILD]-(parent) WITH parent, collect(node.text) as chunks, max(score) AS score // deduplicate parents RETURN parent.title + reduce(r="", c in chunks | r + "\n\n" + c.text) AS text, score, {source:parent.url} AS metadata ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.