Skip to content

[Perf] Move Neo4j cosine similarity to server-side #136

@ishaanxgupta

Description

@ishaanxgupta

Description
search_events_by_embedding fetches every event with an embedding from Neo4j, transfers all embedding vectors to Python, and then computes cosine similarity using NumPy. This is O(N) in the number of events per user, which wastes memory and bandwidth.

Code Reference
src/graph/neo4j_client.py - search_events_by_embedding()

Proposed Fix
Push the cosine computation into the Neo4j Cypher query using gds.similarity.cosine() (or native vector index search) and use ORDER BY score DESC LIMIT $top_k. This reduces data transfer to only the top_k rows.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions