Skip to content

7.4 ai.score — the per-row rerank

MATCH (me:AssistantUser)-[:TRACKS]->(n:NewsItem)
RETURN n.title, n.url
ORDER BY ai.score(n, 'relevance to my Series A funding round') DESC
LIMIT 5

Means: “rank the fetched news by how well each fits, and give me the top five” — the highest-value retrieval lever, a learned relevance sort where no orderable property exists.

How it executes:

  • Fetch as above.
  • Judge — the same batched 0..1 scoring as ai.relevant (the two share one judgment; a query using both scores once and both filters and ranks off it). Every row is kept and its score stamped under the internal ai_score property.
  • Rewrite & run. Neo4j has no ai.score function, so the executor rewrites the call in the executed query to coalesce(n.ai_score, 0.0) (0.0 for any row that wasn’t scored), and ORDER BY … DESC LIMIT k ranks and truncates against the stamp.

The idiomatic filter-then-rank: WHERE ai.relevant(n, '…') … ORDER BY ai.score(n, '…') DESC LIMIT k — narrow to the relevant, then order the survivors by fit.