From b5b4afcf092ac156b80a6ed20b4bfa2c685c5740 Mon Sep 17 00:00:00 2001 From: christoph seiler Date: Sat, 24 Aug 2024 21:59:20 +0200 Subject: [PATCH] chore: adapt similarity and logging --- .../TrackNodeNeo4JDataSource.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/TrackMate.Backend.Neo4J/TrackNodeNeo4JDataSource.cs b/src/TrackMate.Backend.Neo4J/TrackNodeNeo4JDataSource.cs index a1d60da..2b20be2 100644 --- a/src/TrackMate.Backend.Neo4J/TrackNodeNeo4JDataSource.cs +++ b/src/TrackMate.Backend.Neo4J/TrackNodeNeo4JDataSource.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Options; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using Neo4j.Driver; using Trackmate.Backend.Embeddings; using Trackmate.Backend.Models; @@ -6,7 +7,9 @@ namespace TrackMate.Backend.Neo4J; -public class TrackNodeNeo4JDataSource(IOptions settings) : ITrackNodeDataSource +public class TrackNodeNeo4JDataSource( + Logger logger, + IOptions settings) : ITrackNodeDataSource { private const string TrackNodeLabel = "TrackNode"; @@ -82,7 +85,7 @@ public async Task FindByEmbeddingAndDistance(PictureEmbeddi string query = @" WITH $Embedding AS search_vector MATCH path = (startNode:TrackNode)-[:PATH*1..10]->(node:TrackNode) - WHERE startNode.Id = $TrackNodeId AND gds.similarity.euclidean(node.embedding, search_vector) > 0.8 + WHERE startNode.Id = $TrackNodeId AND gds.similarity.euclidean(node.embedding, search_vector) > 0.5 RETURN node, gds.similarity.euclidean(node.embedding, search_vector) AS similarity, length(path) AS numberOfEdges ORDER BY similarity DESC"; @@ -104,6 +107,11 @@ public async Task FindByEmbeddingAndDistance(PictureEmbeddi return FoundTrackNodeModel.None; } + logger.LogInformation("Found track node {TrackNodeId} with similarity {Similarity} and distance {Distance}.", + node["Id"].As(), + record["similarity"].As(), + record["numberOfEdges"].As()); + return new FoundTrackNodeModel( Guid.Parse(node["Id"].As()), Similarity: record["similarity"].As(),