MATIH Platform is in active MVP development. Documentation reflects current implementation status.
14. Context Graph & Ontology
Search Services
Semantic Search

Semantic Search

Semantic search uses vector embeddings to find entities, decisions, and patterns based on meaning rather than exact keyword matches. The Context Graph generates embeddings for entity descriptions, decision rationale, agent trajectories, and query patterns, then uses approximate nearest neighbor (ANN) search to find similar items.


How It Works

  1. The user query is converted into an embedding vector using the configured embedding model
  2. The vector is compared against stored embeddings in the appropriate Pinecone namespace
  3. Results are ranked by cosine similarity score
  4. Optional graph context expansion adds structural relationships around each result

Search API

from context_graph.services.semantic_search_service import (
    SemanticSearchService,
    SearchQuery,
    SearchMode,
    SearchScope,
    SearchFilters,
)
 
results = await service.search(SearchQuery(
    query="customer churn prediction models",
    tenant_id="acme",
    mode=SearchMode.SEMANTIC,
    scope=SearchScope.ENTITIES,
    top_k=10,
    min_score=0.5,
    filters=SearchFilters(
        entity_types=["model", "feature"],
    ),
))

Embedding Namespaces

Different types of searches use different embedding namespaces:

Search TargetNamespaceDimensions
Entity descriptionsENTITY_SEMANTIC1536
Entity graph structureENTITY_STRUCTURAL128
Decision rationaleDECISION_RATIONALE1536
Agent trajectoriesTRAJECTORY256
Query patternsQUERY_PATTERN1536

Scoring

Results are scored using cosine similarity between the query vector and stored vectors:

score = dot(query_vector, stored_vector) / (norm(query) * norm(stored))

Scores range from 0 (no similarity) to 1 (identical). Results below min_score are filtered out.


Natural Language Query Support

The semantic search service accepts natural language queries and automatically:

  1. Extracts intent and entities from the query text
  2. Generates an embedding vector from the query
  3. Selects the appropriate embedding namespace based on the detected intent
  4. Returns results with explanations of why each result matched

Example Queries

QueryWhat It Finds
"Find datasets similar to sales_data"Datasets with similar descriptions to sales_data
"Show me models trained on customer features"Models whose descriptions mention customer features
"What decisions were made about fraud detection?"Decisions with rationale related to fraud detection
"Find all entities related to the recommendation pipeline"Entities semantically similar to recommendation pipelines

Performance Considerations

  • Pinecone ANN search typically completes in under 50ms for up to 10 million vectors
  • Query vector generation adds 100-200ms depending on the embedding model
  • Graph context expansion adds 50-100ms per result when enabled
  • For latency-sensitive paths, disable graph expansion with include_graph_context=False