diff --git a/src/omop_graph/graph/kg.py b/src/omop_graph/graph/kg.py index 3ae9a8e..e2c0ddc 100644 --- a/src/omop_graph/graph/kg.py +++ b/src/omop_graph/graph/kg.py @@ -195,7 +195,7 @@ def emb(self) -> "EmbeddingWriterInterface | EmbeddingReaderInterface": backend_type = self._emb_config.backend_type or cfg.backend faiss_cache_dir = cfg.faiss_cache_dir - backend = resolve_backend(backend_type) + backend = resolve_backend(backend_type, sqlite_path=cfg.sqlite_path) if self._emb_config.client is not None: # Write-capable interface diff --git a/src/omop_graph/graph/paths.py b/src/omop_graph/graph/paths.py index 6217de5..82759e3 100644 --- a/src/omop_graph/graph/paths.py +++ b/src/omop_graph/graph/paths.py @@ -29,7 +29,6 @@ ) # Local Application Imports -from omop_graph.config import OmopGraphConfig from omop_graph.extensions.omop_alchemy import PredicateKind from omop_graph.graph.edges import EdgeView from omop_graph.graph.traverse import GraphTrace, TraceStep @@ -219,9 +218,9 @@ def find_shortest_paths( source: int, target: int, predicate_kinds: Optional[frozenset[PredicateKind]] = None, - max_depth: Optional[int] = None, + max_depth: int = 6, on: Optional[Any] = None, - max_paths: Optional[int] = None, + max_paths: int = 20, traced: bool = False, within_domain: bool = True, ) -> Tuple[List[GraphPath], Optional[GraphTrace]]: @@ -256,12 +255,6 @@ def find_shortest_paths( tuple[list[GraphPath], GraphTrace | None] A list of paths and optionally the trace object. """ - cfg = OmopGraphConfig.get_config() - if max_depth is None: - max_depth = cfg.max_depth - if max_paths is None: - max_paths = cfg.max_paths - if source == target: path = GraphPath(steps=()) trace = ( @@ -429,9 +422,9 @@ def find_shortest_paths_batch( source: int, target: int, predicate_kinds: Union[Set[PredicateKind], frozenset[PredicateKind], None] = None, - max_depth: Optional[int] = None, + max_depth: int = 6, on: Optional[Any] = None, - max_paths: Optional[int] = None, + max_paths: int = 20, within_domain: bool = True, ) -> List[GraphPath]: """ @@ -469,12 +462,6 @@ def find_shortest_paths_batch( if source == target: return [GraphPath(steps=())] - cfg = OmopGraphConfig.get_config() - if max_depth is None: - max_depth = cfg.max_depth - if max_paths is None: - max_paths = cfg.max_paths - # Frontiers: The set of nodes we are currently expanding fwd_frontier = {source} bwd_frontier = {target} @@ -702,7 +689,7 @@ def find_standard_paths( targets: Optional[Tuple[int, ...]], candidate: CandidateHit, predicate_kinds: Optional[frozenset[Any]] = None, - max_depth: Optional[int] = None, + max_depth: int = 6, max_concepts: Optional[int] = None, within_domain: bool = True, ) -> List[StandardConcept]: @@ -746,10 +733,10 @@ def find_standard_paths( Allowed edge types for traversal. Defaults to all kinds when None. Callers in the grounding pipeline pass PredicateKind.IDENTITY exclusively, limiting traversal to Maps-to relationships between non-standard and standard concepts. - max_depth : int, optional + max_depth : int Maximum min_levels_of_separation permitted in the concept_ancestor check when ``targets`` is given, or maximum identity-hop count permitted when ``targets`` - is None. Defaults to OmopGraphConfig.max_depth when None. + is None. Defaults to ``6``. max_concepts : int, optional Per-target cap on unique standard concepts collected (or an overall cap when ``targets`` is None). Once every bucket has reached this count the search @@ -778,10 +765,7 @@ def find_standard_paths( admissible heuristic added to the priority. """ # Placeholder for the non-parent-ID grounding so the target accumulation works - unconstrained_placeholder: int = 0 - - if max_depth is None: - max_depth = OmopGraphConfig.get_config().max_depth + unconstrained_placeholder: int = 0 source_view = kg.concept_view(candidate.concept_id) source_is_std = source_view.standard_concept if source_view else False diff --git a/src/omop_graph/reasoning/grounding.py b/src/omop_graph/reasoning/grounding.py index 689b9fb..b0cc5ca 100644 --- a/src/omop_graph/reasoning/grounding.py +++ b/src/omop_graph/reasoning/grounding.py @@ -16,12 +16,11 @@ from __future__ import annotations import logging -from dataclasses import dataclass, field +from dataclasses import dataclass from typing import List, Optional, Tuple import numpy as np -from omop_graph.config import OmopGraphConfig from omop_graph.extensions.omop_alchemy import PredicateKind from omop_graph.graph.constraints import SearchConstraintConcept from omop_graph.graph.kg import KnowledgeGraph @@ -74,9 +73,7 @@ class GroundingConstraints: parent_ids: Optional[Tuple[int, ...]] search_constraint: Optional[SearchConstraintConcept] - max_depth: int = field( - default_factory=lambda: OmopGraphConfig.get_config().max_depth - ) + max_depth: int = 6 predicate_kinds: frozenset[PredicateKind] = frozenset({PredicateKind.IDENTITY}) def __post_init__(self) -> None: