GenAI and GraphRAG

retriever

A component that searches a data source and returns the information relevant to a query. Often used to provide context for a language model.

Also written: retrievers

Example

A retriever that searches plots, then reads the graph around each film it finds.

cypher
WITH ai.text.embed(
    "A mysterious spaceship lands Earth",
    "OpenAI",
    { token: "sk-...", model: "text-embedding-ada-002" }
) AS myMoviePlot
 
MATCH (node:Movie)
SEARCH node IN (
  VECTOR INDEX moviePlots
  FOR myMoviePlot
  LIMIT 6
) SCORE AS score
 
MATCH (node)<-[r:RATED]-()
RETURN
  node.title AS title, node.plot AS plot, score AS similarityScore,
  collect { MATCH (node)-[:IN_GENRE]->(g) RETURN g.name } as genres,
  collect { MATCH (node)<-[:ACTED_IN]->(a) RETURN a.name } as actors,
  avg(r.rating) as userRating
ORDER BY userRating DESC

The example query here performs graph-enhanced vector retrieval. First it embeds the prompt, then finds a list of nearest neighbours by semantic similarity. Finally, it traverses a single relationship to gather rating properties.

A retriever is not required to use embeddings or graph to be defined as a retriever.

Lessons that use this term

The lesson and course links below open in a new tab.

No published lesson uses this term yet.

All glossary terms