Skip to content

Wire Neo4j heuristics into the search fitness function - #1731

Open
andyfelder16 wants to merge 10 commits into
masterfrom
neo4j-fitness-integration
Open

Wire Neo4j heuristics into the search fitness function#1731
andyfelder16 wants to merge 10 commits into
masterfrom
neo4j-fitness-integration

Conversation

@andyfelder16

@andyfelder16 andyfelder16 commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Last of the PRs splitting #1641, on top of #1580, #1672, #1647, #1697 and #1715, all of which are merged. It closes the chain: the Cypher queries the SUT runs have been captured since #1460, and this is what finally turns them into search guidance.

  • Neo4jHandler collects the queries intercepted from Session.run, reads the graph once per action rather than once per query, and scores each query against that snapshot. Only MATCH queries are scored; anything that does not parse as one, such as a write, is skipped
  • Neo4jCommandWithDistance and Neo4jDistanceWithMetrics carry the result to the DTO
  • EnterpriseFitness.handleNeo4jHeuristics feeds the distances to the search, behind the new heuristicsForNeo4j option, and reports evaluation counts and the average number of nodes inspected through Statistics
  • Nothing throws back at the SUT: a driver that cannot be queried, a query that does not parse, and a scoring failure each degrade to no heuristic or to a failed evaluation, and the search carries on
  • 5 handler tests plus one in StatisticsTest, covering the scored path, a write being skipped, no driver, heuristics disabled, and a driver that cannot be reached

@andyfelder16
andyfelder16 marked this pull request as ready for review September 1, 2026 14:59
* @param evaluationFailure whether the evaluation failed
*/
public Neo4jDistanceWithMetrics(double distance, int numberOfEvaluatedNodes, boolean evaluationFailure) {
if (distance < 0.0d || distance > 1.0d || Double.isNaN(distance)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @andyfelder16 .thx ;) but should first request @jgaleotti review, and, then, once that is completed, JP asks for my review. anyway, with a quick look here i can see the naming is confusing. see DistanceHelper for a definition of distance vs heuristic inside EM codebase

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @arcuri82 , I am taking over the review. However, this is indeed a distance since it follows the same model as MongoDistanceWithMetrics, RedisDistanceWithMetrics, DynamoDbDistanceWithMetrics and CqlDistanceWithMetrics (i.e., Cassandra)

* @param evaluationFailure whether the evaluation failed
*/
public Neo4jDistanceWithMetrics(double distance, int numberOfEvaluatedNodes, boolean evaluationFailure) {
if (distance < 0.0d || distance > 1.0d || Double.isNaN(distance)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @arcuri82 , I am taking over the review. However, this is indeed a distance since it follows the same model as MongoDistanceWithMetrics, RedisDistanceWithMetrics, DynamoDbDistanceWithMetrics and CqlDistanceWithMetrics (i.e., Cassandra)

metrics = new Neo4jDistanceWithMetrics(distance, graph.nodeCount(), false);
} catch (Exception e) {
SimpleLogger.uniqueWarn("Failed to compute Neo4j heuristic for query: " + query);
metrics = new Neo4jDistanceWithMetrics(1.0, graph.nodeCount(), true);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace 1.0 with Neo4HeuristicsCalculator.MAX_NEO4J_DISTANCE = 1.0d

.toList()

if (toMinimize.isNotEmpty()) {
fv.setExtraToMinimize(i, toMinimize)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code is behind master

@jgaleotti

Copy link
Copy Markdown
Collaborator

@andyfelder16 please update branch and fix conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants