Skip to main content

link_memory_notes

Function link_memory_notes 

Source
pub async fn link_memory_notes(
    entity_ids: &[i64],
    pool: SqlitePool,
    embedding_store: Arc<EmbeddingStore>,
    provider: AnyProvider,
    cfg: &NoteLinkingConfig,
) -> LinkingStats
Expand description

Link newly extracted entities to semantically similar entities in the graph.

For each entity in entity_ids:

  1. Load the entity name + summary from SQLite.
  2. Embed all entity texts in parallel.
  3. Search the entity embedding collection in parallel for the top_k + 1 most similar points.
  4. Filter out the entity itself (by qdrant_point_id or entity_id payload) and points below similarity_threshold.
  5. Insert a unidirectional similar_to edge where source_id < target_id to avoid double-counting in BFS recall while still being traversable via the OR clause in edges_for_entity. The edge confidence is set to the cosine similarity score.
  6. Deduplicate pairs within a single pass so that a pair encountered from both A→B and B→A directions is only inserted once, keeping edges_created accurate.

Errors are logged and not propagated — this is a best-effort background enrichment step.