Skip to content

Commit

Permalink
chore: adapt similarity and logging
Browse files Browse the repository at this point in the history
  • Loading branch information
seilc1 committed Aug 24, 2024
1 parent 0bebcd0 commit b5b4afc
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/TrackMate.Backend.Neo4J/TrackNodeNeo4JDataSource.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Neo4j.Driver;
using Trackmate.Backend.Embeddings;
using Trackmate.Backend.Models;
using Trackmate.Backend.TrackNodes;

namespace TrackMate.Backend.Neo4J;

public class TrackNodeNeo4JDataSource(IOptions<TrackNodeNeo4JDataSourceSettings> settings) : ITrackNodeDataSource
public class TrackNodeNeo4JDataSource(
Logger<TrackNodeNeo4JDataSource> logger,
IOptions<TrackNodeNeo4JDataSourceSettings> settings) : ITrackNodeDataSource
{
private const string TrackNodeLabel = "TrackNode";

Expand Down Expand Up @@ -82,7 +85,7 @@ public async Task<FoundTrackNodeModel> 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";

Expand All @@ -104,6 +107,11 @@ public async Task<FoundTrackNodeModel> FindByEmbeddingAndDistance(PictureEmbeddi
return FoundTrackNodeModel.None;
}

logger.LogInformation("Found track node {TrackNodeId} with similarity {Similarity} and distance {Distance}.",
node["Id"].As<string>(),
record["similarity"].As<double>(),
record["numberOfEdges"].As<double>());

return new FoundTrackNodeModel(
Guid.Parse(node["Id"].As<string>()),
Similarity: record["similarity"].As<double>(),
Expand Down

0 comments on commit b5b4afc

Please sign in to comment.