Skip to content

Commit

Permalink
update LiteralString import
Browse files Browse the repository at this point in the history
  • Loading branch information
prasmussen15 committed Nov 24, 2024
1 parent d0d93bb commit 1ca6dac
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
3 changes: 2 additions & 1 deletion graphiti_core/edges.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
from abc import ABC, abstractmethod
from datetime import datetime
from time import time
from typing import Any, LiteralString
from typing import Any
from uuid import uuid4

from neo4j import AsyncDriver
from pydantic import BaseModel, Field
from typing_extensions import LiteralString

from graphiti_core.embedder import EmbedderClient
from graphiti_core.errors import EdgeNotFoundError, GroupsEdgesNotFoundError
Expand Down
3 changes: 2 additions & 1 deletion graphiti_core/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
from datetime import datetime, timezone
from enum import Enum
from time import time
from typing import Any, LiteralString
from typing import Any
from uuid import uuid4

from neo4j import AsyncDriver
from pydantic import BaseModel, Field
from typing_extensions import LiteralString

from graphiti_core.embedder import EmbedderClient
from graphiti_core.errors import NodeNotFoundError
Expand Down
24 changes: 23 additions & 1 deletion graphiti_core/search/search_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

logger = logging.getLogger(__name__)

RELEVANT_SCHEMA_LIMIT = 3
RELEVANT_SCHEMA_LIMIT = 10
DEFAULT_MIN_SCORE = 0.6
DEFAULT_MMR_LAMBDA = 0.5
MAX_SEARCH_DEPTH = 3
Expand Down Expand Up @@ -605,6 +605,28 @@ async def get_relevant_edges(
relevant_edge_uuids.add(edge.uuid)
relevant_edges.append(edge)

query: LiteralString = """
UNWIND $edges AS edge
MATCH (n:Entity {uuid: $source_uuid})-[r:RELATES_TO {group_id: edge.group_id}]->(m:Entity {uuid: $target_uuid})
WITH n, m, r, vector.similarity.cosine(r.fact_embedding, edge.fact_embedding) AS score
WHERE score > $min_score
RETURN
r.uuid AS uuid,
r.group_id AS group_id,
n.uuid AS source_node_uuid,
m.uuid AS target_node_uuid,
r.created_at AS created_at,
r.name AS name,
r.fact AS fact,
r.fact_embedding AS fact_embedding,
r.episodes AS episodes,
r.expired_at AS expired_at,
r.valid_at AS valid_at,
r.invalid_at AS invalid_at
ORDER BY score DESC
LIMIT $limit
"""

end = time()
logger.debug(f'Found relevant edges: {relevant_edge_uuids} in {(end - start) * 1000} ms')

Expand Down

0 comments on commit 1ca6dac

Please sign in to comment.