graphquery

package
v1.0.0-alpha.48 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 23 Imported by: 0

README

Graph Query Coordinator

Query coordinator that orchestrates retrieval operations across the graph subsystem using PathRAG, GraphRAG, and static routing patterns.

Overview

The graph-query component serves as the central coordination layer for all graph query operations. It provides three primary capabilities:

  • PathRAG: Multi-hop graph traversal with path tracking and relevance scoring
  • GraphRAG: Community-aware search leveraging graph clustering for semantic and structural queries
  • Static Routing: Query-type-to-subject mapping for distributed graph components

The component implements graceful degradation, enabling partial functionality when optional dependencies like community indices are unavailable during cluster startup.

Architecture

flowchart TD
    Client[Query Client] -->|NATS Request| GQ[graph-query]

    GQ -->|Entity Queries| GI[graph-ingest]
    GQ -->|Relationships| GX[graph-index]
    GQ -->|Semantic Search| GE[graph-embedding]
    GQ -->|Communities| GC[graph-clustering]

    GQ -->|PathRAG| PathSearcher[PathSearcher<br/>BFS Traversal]
    GQ -->|GraphRAG| GraphRAG[GraphRAG Engine<br/>Community Search]
    GQ -->|Route| Router[StaticRouter<br/>Subject Mapping]

    PathSearcher -->|Fetch Entities| GI
    PathSearcher -->|Fetch Relationships| GX

    GraphRAG -->|Community Lookup| Cache[CommunityCache<br/>KV Watcher]
    GraphRAG -->|Load Entities| GI
    GraphRAG -->|Semantic Search| GE

    Cache -->|Watch| KV[(COMMUNITY_INDEX<br/>KV Bucket)]

    style GQ fill:#4a90e2,color:#fff
    style PathSearcher fill:#7cb342,color:#fff
    style GraphRAG fill:#7cb342,color:#fff
    style Cache fill:#ffa726,color:#fff

Features

PathRAG Traversal

BFS-based graph traversal with comprehensive path tracking:

  • Multi-hop exploration with configurable depth limits
  • Direction control: outgoing, incoming, or bidirectional
  • Predicate filtering for focused traversal
  • Decay-weighted relevance scoring (0.8 per hop)
  • Full path reconstruction from start to discovered entities
  • Max nodes and max paths limits for bounded execution

Tiered search strategy with automatic fallback:

Tier 0: Path Intent Detection

  • Keyword classifier detects path traversal patterns in natural language
  • Resolves partial entity IDs to canonical form
  • Executes PathRAG without requiring embeddings

Tier 1: Semantic Search

  • Neural embedding-based similarity via graph-embedding component
  • Returns entities ranked by semantic relevance
  • Automatic community attribution

Tier 2: Text-Based Fallback

  • Community summary scoring using statistical methods
  • Keyword matching across summaries and entity properties
  • Works without embeddings for degraded scenarios
Static Routing

Fixed query-type-to-subject mappings for all graph operations:

Query Type Target Component Subject Pattern
entity, entityBatch, entityPrefix graph-ingest graph.ingest.query.*
outgoing, incoming, alias, predicate graph-index graph.index.query.*
spatial, temporal graph-spatial, graph-temporal graph.*.query.*
semantic, similar graph-embedding graph.embedding.query.*
community graph-clustering graph.clustering.query.*

Configuration

{
  "type": "processor",
  "name": "graph-query",
  "config": {
    "ports": {
      "inputs": [
        {"name": "query_entity", "type": "nats-request", "subject": "graph.query.entity"},
        {"name": "query_relationships", "type": "nats-request", "subject": "graph.query.relationships"},
        {"name": "query_path_search", "type": "nats-request", "subject": "graph.query.pathSearch"},
        {"name": "local_search", "type": "nats-request", "subject": "graph.query.localSearch"},
        {"name": "global_search", "type": "nats-request", "subject": "graph.query.globalSearch"}
      ]
    },
    "query_timeout": "5s",
    "max_depth": 10,
    "startup_attempts": 10,
    "startup_interval": "500ms",
    "recheck_interval": "5s"
  }
}
Configuration Fields
Field Type Default Description
ports PortConfig Required Input port definitions for query subscriptions
query_timeout time.Duration 5s Timeout for inter-component NATS requests
max_depth int 10 Maximum BFS traversal depth for PathRAG
startup_attempts int 10 Bucket availability check attempts at startup
startup_interval time.Duration 500ms Interval between startup availability checks
recheck_interval time.Duration 5s Interval for rechecking missing buckets after startup

Query Types

Entity Queries

Query Entity by ID

{
  "subject": "graph.query.entity",
  "data": {"id": "acme.ops.robotics.gcs.drone.001"}
}

Query Entity by Alias

{
  "subject": "graph.query.entityByAlias",
  "data": {"aliasOrID": "drone001"}
}

Resolves alias to canonical ID via graph-index, then fetches entity.

Hierarchy Stats

{
  "subject": "graph.query.hierarchyStats",
  "data": {"prefix": "acme.ops"}
}

Returns child node counts grouped by next hierarchy level.

Relationship Queries

Outgoing/Incoming Relationships

{
  "subject": "graph.query.relationships",
  "data": {
    "entity_id": "acme.ops.robotics.gcs.drone.001",
    "direction": "outgoing"
  }
}

Direction: outgoing (default), incoming.

PathRAG

Path Search Request

{
  "subject": "graph.query.pathSearch",
  "data": {
    "start_entity": "acme.ops.robotics.gcs.drone.001",
    "max_depth": 3,
    "max_nodes": 100,
    "direction": "outgoing",
    "predicates": ["connectedTo", "partOf"],
    "timeout": "10s",
    "max_paths": 50
  }
}

Response Format

{
  "entities": [
    {"id": "acme.ops.robotics.gcs.drone.001", "type": "entity", "score": 1.0},
    {"id": "acme.ops.robotics.nav.module.042", "type": "entity", "score": 0.8}
  ],
  "paths": [
    [],
    [
      {"from": "acme.ops.robotics.gcs.drone.001", "predicate": "hasComponent",
       "to": "acme.ops.robotics.nav.module.042"}
    ]
  ],
  "truncated": false
}
GraphRAG

Local Search

Community-scoped search starting from a known entity:

{
  "subject": "graph.query.localSearch",
  "data": {
    "entity_id": "acme.ops.robotics.gcs.drone.001",
    "query": "navigation system",
    "level": 0
  }
}

Global Search

Cross-community search with tiered strategy:

{
  "subject": "graph.query.globalSearch",
  "data": {
    "query": "autonomous navigation systems",
    "level": 1,
    "max_communities": 5,
    "include_summaries": true,
    "include_relationships": false,
    "include_sources": false
  }
}

Global Search Response

{
  "entities": [...],
  "community_summaries": [
    {
      "community_id": "L0_C3",
      "summary": "Navigation and control systems...",
      "keywords": ["navigation", "control", "autonomous"],
      "level": 0,
      "relevance": 0.95
    }
  ],
  "count": 42,
  "duration_ms": 245
}
Semantic Queries

Semantic Search

{
  "subject": "graph.query.semantic",
  "data": {
    "query": "flight control algorithms",
    "limit": 50
  }
}

Similar Entities

{
  "subject": "graph.query.similar",
  "data": {
    "entity_id": "acme.ops.robotics.nav.module.042",
    "limit": 20
  }
}
Spatial/Temporal Queries

Spatial Query

{
  "subject": "graph.query.spatial",
  "data": {
    "min_lat": 37.7,
    "max_lat": 37.8,
    "min_lon": -122.5,
    "max_lon": -122.4
  }
}

Temporal Query

{
  "subject": "graph.query.temporal",
  "data": {
    "start_time": "2026-01-01T00:00:00Z",
    "end_time": "2026-02-01T00:00:00Z"
  }
}

Graceful Degradation

The component uses resource watchers to handle missing optional dependencies:

  1. Startup Phase: Attempts to connect to COMMUNITY_INDEX bucket (10 attempts over 5 seconds by default)
  2. Degraded Mode: If bucket unavailable, PathRAG and static routing work, GraphRAG disabled
  3. Recovery: Background checking continues at recheck_interval
  4. Restoration: When bucket becomes available, GraphRAG is automatically enabled

Lifecycle reporting tracks degraded states via COMPONENT_STATUS KV bucket:

  • waiting_for_COMMUNITY_INDEX: Checking for bucket during startup
  • degraded_missing_COMMUNITY_INDEX: Bucket unavailable, GraphRAG disabled
  • idle: All dependencies available, normal operation
  • querying: Processing queries (throttled reporting)

Input Ports

Port Name Type Subject Purpose
query_entity nats-request graph.query.entity Entity lookup by ID
query_entity_by_alias nats-request graph.query.entityByAlias Entity resolution by alias
query_relationships nats-request graph.query.relationships Relationship queries
query_path_search nats-request graph.query.pathSearch PathRAG traversal
query_hierarchy_stats nats-request graph.query.hierarchyStats Hierarchy statistics
query_prefix nats-request graph.query.prefix Prefix-based entity lookup
query_spatial nats-request graph.query.spatial Spatial bounding box queries
query_temporal nats-request graph.query.temporal Temporal range queries
query_semantic nats-request graph.query.semantic Neural semantic search
query_similar nats-request graph.query.similar Similar entity search
local_search nats-request graph.query.localSearch Community-scoped search
global_search nats-request graph.query.globalSearch Cross-community NL search

Output Ports

None. The component uses request/reply pattern and returns results directly to callers.

Metrics

Prometheus metrics exported for observability:

Metric Type Labels Description
graph_query_duration_seconds Histogram query_type Query latency distribution
graph_query_cache_hits_total Counter - Community cache hits
graph_query_cache_misses_total Counter - Community cache misses
graph_query_storage_hits_total Counter - Storage fallback successes
graph_query_storage_misses_total Counter - Storage fallback failures

PathRAG Algorithm Details

The PathSearcher implements BFS with parent tracking:

  1. Verification: Confirm start entity exists via graph-ingest
  2. BFS Traversal: Follow relationships via graph-index queries
  3. Parent Tracking: Record (parent, predicate) for each discovered entity
  4. Scoring: Calculate decay score: score = 0.8^depth
  5. Path Reconstruction: Walk parent chain backwards, reverse to get forward path

Limits:

  • max_depth: Stop traversal at depth limit (default: 10)
  • max_nodes: Stop after visiting N entities (default: 100)
  • max_paths: Limit returned paths (default: unlimited)

Direction Control:

  • outgoing: Follow edges from entity to targets
  • incoming: Follow edges from sources to entity
  • both: Merge outgoing and incoming (deduplication by target + predicate)

Predicate Filtering: Empty array means all predicates; non-empty filters to specified predicates only.

GraphRAG Search Strategy

Tier 0: Path Intent (Structural tier, no embeddings required)

  • Classify query for path traversal patterns
  • Resolve partial entity IDs via suffix matching
  • Execute PathRAG if start node identified

Tier 1: Semantic Search (Requires graph-embedding)

  • Query graph-embedding with natural language
  • Receive entity IDs ranked by embedding similarity
  • Map entities to communities via cache
  • Load full entity data via graph-ingest

Tier 2: Text-Based Fallback (Works without embeddings)

  • Score communities by summary/keyword matching
  • Select top-N communities by score
  • Load all entities from selected communities
  • Filter entities by query term matching
  1. Lookup entity's community at requested level (cache, then storage fallback)
  2. If not in community, fall back to semantic search
  3. Load all community members via batch query
  4. Filter members by query terms

Thread Safety

The component is safe for concurrent use. Query handlers process requests concurrently via NATS subscription workers. Internal state is protected by read-write mutexes.

See Also

Documentation

Overview

Package graphquery community cache implementation

Package graphquery implements the query coordinator component for the graph subsystem. It orchestrates queries across graph-ingest and graph-index components and provides PathRAG traversal capabilities.

Package graphquery implements the query coordinator component for the graph subsystem.

Overview

The graphquery package orchestrates queries across graph subsystem components (graph-ingest, graph-index, graph-embedding, graph-clustering) and provides advanced retrieval capabilities:

  • PathRAG: Graph traversal with path tracking and relevance scoring
  • GraphRAG: Community-aware retrieval (local and global search)
  • Static routing: Query-type-to-subject mapping for distributed components

The component handles graceful degradation when optional features (like community detection) are unavailable, enabling partial functionality during cluster startup.

Architecture

┌──────────────────────────────────────────────────────────────────────────┐
│                       graph-query Component                              │
├──────────────────────────────────────────────────────────────────────────┤
│  StaticRouter    │  PathSearcher   │  CommunityCache  │  GraphRAG       │
│  (query routing) │  (BFS traversal)│  (KV watcher)    │  (search)       │
└──────────────────────────────────────────────────────────────────────────┘
           ↓                ↓                  ↓                 ↓
┌────────────────┬────────────────┬────────────────┬────────────────────────┐
│  graph-ingest  │  graph-index   │  graph-embed   │  graph-clustering      │
│  (entity data) │  (relationships)│  (semantic)   │  (communities)         │
└────────────────┴────────────────┴────────────────┴────────────────────────┘

Usage

The component is created via the factory pattern:

err := graphquery.Register(registry)

Or configured in a flow definition:

{
    "type": "processor",
    "name": "graph-query",
    "config": {
        "ports": {
            "inputs": [
                {"name": "query_entity", "type": "nats-request", "subject": "graph.query.entity"},
                {"name": "query_relationships", "type": "nats-request", "subject": "graph.query.relationships"},
                {"name": "query_path_search", "type": "nats-request", "subject": "graph.query.pathSearch"}
            ]
        },
        "query_timeout": "5s",
        "max_depth": 10
    }
}

Query Types

PathRAG (graph.query.pathSearch):

BFS-based graph traversal with path tracking and relevance scoring:

{
    "start_entity": "org.platform.domain.system.type.instance",
    "max_depth": 3,
    "max_nodes": 100,
    "include_siblings": false
}

Response includes discovered entities, full paths from start, and decay-weighted scores.

Local Search (graph.query.localSearch):

Community-scoped search for entities related to a starting entity:

{
    "entity_id": "org.platform.domain.system.type.instance",
    "query": "navigation system",
    "level": 0
}

Returns entities from the same community that match the query.

Global Search (graph.query.globalSearch):

Tiered search across all communities:

{
    "query": "autonomous navigation",
    "level": 1,
    "max_communities": 5
}

Uses semantic search first (if available), then falls back to text-based scoring.

Static Routing

Query types are routed to fixed NATS subjects:

Entity queries → graph.ingest.query.*
Relationship queries → graph.index.query.*
Semantic queries → graph.embedding.query.*
Community queries → graph.clustering.query.*

Graceful Degradation

The component uses resource.Watcher for optional dependencies:

  • If COMMUNITY_INDEX bucket unavailable at startup, PathRAG works but GraphRAG is disabled
  • When bucket becomes available later, GraphRAG is enabled automatically
  • Lifecycle reporting tracks degraded states for observability

Configuration

Configuration options:

QueryTimeout:     5s     # Timeout for inter-component requests
MaxDepth:         10     # Maximum BFS traversal depth
StartupAttempts:  10     # Attempts to find optional buckets at startup
StartupInterval:  500ms  # Interval between startup attempts
RecheckInterval:  5s     # Interval for rechecking missing buckets

PathRAG Algorithm

The PathSearcher uses BFS with parent tracking:

  1. Verify start entity exists via graph-ingest
  2. BFS traversal following outgoing relationships via graph-index
  3. Track parent info for each discovered entity
  4. Calculate relevance scores with exponential decay (0.8 per hop by default)
  5. Reconstruct full paths from start to each discovered entity

Limits prevent unbounded traversal:

  • MaxDepth: stops traversal at depth limit
  • MaxNodes: stops after visiting N entities

Global search uses a tiered approach:

  1. Tier 1: Semantic search via graph-embedding (embedding similarity)
  2. Tier 2: Text-based scoring of community summaries
  3. Load entities from top-N matching communities
  4. Filter entities by query terms

Local search:

  1. Look up entity's community from cache
  2. Fallback to storage query if cache miss
  3. Fallback to semantic search if no community
  4. Load and filter community members

Thread Safety

The Component is safe for concurrent use. Query handlers process requests concurrently via NATS subscription workers.

Metrics

The package exports Prometheus metrics:

  • graph_query_duration_seconds: Query latency histogram
  • graph_query_cache_hits_total: Community cache hits
  • graph_query_cache_misses_total: Community cache misses
  • graph_query_storage_hits_total: Storage fallback hits
  • graph_query_storage_misses_total: Storage fallback misses

See Also

Related packages:

Package graphquery entity ID resolution

Package graphquery GraphRAG search handlers

Package graphquery provides Prometheus metrics for graph-query component.

Package graphquery PathRAG algorithm implementation

Package graphquery query handlers

Index

Constants

View Source
const (
	// DefaultMaxCommunities is the default number of communities to search in GlobalSearch
	DefaultMaxCommunities = 5

	// MaxTotalEntitiesInSearch limits the total number of entities that can be loaded
	// across all communities in GlobalSearch to prevent unbounded memory usage
	MaxTotalEntitiesInSearch = 10000

	// ScoreWeightSummary is the weight for summary text matches in community scoring
	ScoreWeightSummary = 2.0

	// ScoreWeightKeyword is the weight for keyword matches in community scoring
	ScoreWeightKeyword = 1.5
)

GraphRAG search constants

View Source
const (
	DirectionOutgoing = "outgoing" // Follow edges from entity to targets (default)
	DirectionIncoming = "incoming" // Follow edges from sources to entity
	DirectionBoth     = "both"     // Follow edges in both directions
)

Direction constants for path traversal

Variables

This section is empty.

Functions

func CreateGraphQuery

func CreateGraphQuery(rawConfig json.RawMessage, deps component.Dependencies) (component.Discoverable, error)

CreateGraphQuery creates a new graph query coordinator component

func Register

func Register(registry *component.Registry) error

Register registers the graph-query component factory with the registry

Types

type CommunityCache

type CommunityCache struct {
	// contains filtered or unexported fields
}

CommunityCache maintains an in-memory cache of communities from COMMUNITY_INDEX KV. It watches the KV bucket for changes and updates the cache in real-time. This is a consumer-owned cache - graph-query owns and manages its own view of community data.

func NewCommunityCache

func NewCommunityCache(logger *slog.Logger) *CommunityCache

NewCommunityCache creates a new community cache.

func (*CommunityCache) GetAllCommunities

func (c *CommunityCache) GetAllCommunities() []*clustering.Community

GetAllCommunities retrieves all communities regardless of level. Returns empty slice if no communities exist.

func (*CommunityCache) GetCommunitiesByLevel

func (c *CommunityCache) GetCommunitiesByLevel(level int) []*clustering.Community

GetCommunitiesByLevel retrieves all communities at a specific level. Returns empty slice if no communities exist at that level.

func (*CommunityCache) GetCommunity

func (c *CommunityCache) GetCommunity(id string) *clustering.Community

GetCommunity retrieves a community by ID. Returns nil if not found.

func (*CommunityCache) GetEntityCommunity

func (c *CommunityCache) GetEntityCommunity(entityID string, level int) *clustering.Community

GetEntityCommunity retrieves the community containing an entity at a specific level. Returns nil if the entity is not in any community at that level.

func (*CommunityCache) IsReady

func (c *CommunityCache) IsReady() bool

IsReady returns true if the initial sync from KV is complete.

func (*CommunityCache) Stats

func (c *CommunityCache) Stats() CommunityStats

Stats returns cache statistics.

func (*CommunityCache) Stop

func (c *CommunityCache) Stop()

Stop stops the watcher if running.

func (*CommunityCache) WatchAndSync

func (c *CommunityCache) WatchAndSync(ctx context.Context, bucket jetstream.KeyValue) error

WatchAndSync starts watching the COMMUNITY_INDEX KV bucket and syncs changes to the cache. This method blocks until the context is cancelled.

type CommunityStats

type CommunityStats struct {
	TotalCommunities int         `json:"total_communities"`
	TotalEntities    int         `json:"total_entities"`
	ByLevel          map[int]int `json:"by_level"`
	Ready            bool        `json:"ready"`
}

CommunityStats provides cache statistics.

type CommunitySummary

type CommunitySummary struct {
	CommunityID string   `json:"community_id"`
	Summary     string   `json:"summary"`
	Keywords    []string `json:"keywords"`
	Level       int      `json:"level"`
	Relevance   float64  `json:"relevance"`
}

CommunitySummary represents a community's summary used in global search

type Component

type Component struct {
	// contains filtered or unexported fields
}

Component implements the graph query coordinator

func (*Component) ConfigSchema

func (c *Component) ConfigSchema() component.ConfigSchema

ConfigSchema returns the JSON schema for the component's configuration

func (*Component) DataFlow

func (c *Component) DataFlow() component.FlowMetrics

DataFlow returns the component's data flow metrics

func (*Component) Health

func (c *Component) Health() component.HealthStatus

Health returns the component's health status

func (*Component) Initialize

func (c *Component) Initialize() error

Initialize initializes the component

func (*Component) InputPorts

func (c *Component) InputPorts() []component.Port

InputPorts returns the component's input ports

func (*Component) Meta

func (c *Component) Meta() component.Metadata

Meta returns component metadata

func (*Component) OutputPorts

func (c *Component) OutputPorts() []component.Port

OutputPorts returns the component's output ports (none for query coordinator)

func (*Component) Start

func (c *Component) Start(ctx context.Context) error

Start starts the component

func (*Component) Stop

func (c *Component) Stop(timeout time.Duration) error

Stop stops the component

type Config

type Config struct {
	Ports           *component.PortConfig `json:"ports,omitempty" schema:"type:ports,description:Port configuration,category:basic"`
	QueryTimeout    time.Duration         `json:"query_timeout,omitempty" schema:"type:duration,description:Timeout for query operations,default:5s,category:basic"`
	MaxDepth        int                   `` /* 136-byte string literal not displayed */
	StartupAttempts int                   `` /* 141-byte string literal not displayed */
	StartupInterval time.Duration         `` /* 134-byte string literal not displayed */
	RecheckInterval time.Duration         `` /* 137-byte string literal not displayed */
}

Config defines the configuration for the graph-query coordinator component

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a default configuration for the graph-query coordinator

func (*Config) ApplyDefaults

func (c *Config) ApplyDefaults()

ApplyDefaults applies default values to the configuration

func (Config) Schema

func (c Config) Schema() component.ConfigSchema

Schema returns the configuration schema for the component

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the configuration

type GlobalSearchRequest

type GlobalSearchRequest struct {
	Query                string `json:"query"`
	Level                int    `json:"level"`
	MaxCommunities       int    `json:"max_communities"`
	IncludeSummaries     *bool  `json:"include_summaries,omitempty"`     // Include community summaries (default: true)
	IncludeRelationships bool   `json:"include_relationships,omitempty"` // Include relationships between entities (default: false)
	IncludeSources       bool   `json:"include_sources,omitempty"`       // Include source attribution (default: false)
}

GlobalSearchRequest is the request format for global search

type GlobalSearchResponse

type GlobalSearchResponse struct {
	Entities           []*gtypes.EntityState `json:"entities"`
	CommunitySummaries []CommunitySummary    `json:"community_summaries,omitempty"`
	Relationships      []Relationship        `json:"relationships,omitempty"`
	Sources            []Source              `json:"sources,omitempty"`
	Count              int                   `json:"count"`
	DurationMs         int64                 `json:"duration_ms"`
	Answer             string                `json:"answer,omitempty"`
	AnswerModel        string                `json:"answer_model,omitempty"`
}

GlobalSearchResponse is the response format for global search

type HierarchyChild

type HierarchyChild struct {
	Prefix string `json:"prefix"`
	Name   string `json:"name"`
	Count  int    `json:"count"`
}

HierarchyChild represents a child node in the hierarchy

type LocalSearchRequest

type LocalSearchRequest struct {
	EntityID string `json:"entity_id"`
	Query    string `json:"query"`
	Level    int    `json:"level"`
}

LocalSearchRequest is the request format for local search

type LocalSearchResponse

type LocalSearchResponse struct {
	Entities    []*gtypes.EntityState `json:"entities"`
	CommunityID string                `json:"communityId"`
	Count       int                   `json:"count"`
	DurationMs  int64                 `json:"durationMs"`
}

LocalSearchResponse is the response format for local search

type PathEntity

type PathEntity struct {
	ID    string  `json:"id"`
	Type  string  `json:"type"`
	Score float64 `json:"score"`
}

PathEntity represents a discovered entity with relevance score

type PathRAGResult

type PathRAGResult struct {
	Entities  []*gtypes.EntityState
	Truncated bool
}

PathRAGResult wraps the result of a PathRAG query for use in handleGlobalSearch. It contains EntityState objects rather than PathEntity for consistency with GlobalSearchResponse.

type PathSearchRequest

type PathSearchRequest struct {
	StartEntity     string   `json:"start_entity"`
	MaxDepth        int      `json:"max_depth"`
	MaxNodes        int      `json:"max_nodes"`
	IncludeSiblings bool     `json:"include_siblings"`
	Direction       string   `json:"direction,omitempty"`  // "outgoing" (default), "incoming", "both"
	Predicates      []string `json:"predicates,omitempty"` // Filter to specific predicates (empty = all)
	Timeout         string   `json:"timeout,omitempty"`    // Request timeout e.g. "5s" (0 = default)
	MaxPaths        int      `json:"max_paths,omitempty"`  // Limit number of paths returned (0 = unlimited)
}

PathSearchRequest defines the request schema for path search queries

type PathSearchResponse

type PathSearchResponse struct {
	Entities  []PathEntity `json:"entities"`
	Paths     [][]PathStep `json:"paths"` // Each path is a sequence of steps from start to entity
	Truncated bool         `json:"truncated"`
}

PathSearchResponse defines the response for path search

type PathSearcher

type PathSearcher struct {
	// contains filtered or unexported fields
}

PathSearcher executes PathRAG traversal with proper path tracking

func NewPathSearcher

func NewPathSearcher(nats natsRequester, timeout time.Duration, maxDepth int, logger *slog.Logger) *PathSearcher

NewPathSearcher creates a new PathSearcher instance

func (*PathSearcher) Search

Search performs BFS traversal with path tracking

type PathStep

type PathStep struct {
	From      string `json:"from"`
	Predicate string `json:"predicate"`
	To        string `json:"to"`
}

PathStep represents a single edge traversal

type Relationship

type Relationship struct {
	FromEntityID string `json:"from_entity_id"`
	ToEntityID   string `json:"to_entity_id"`
	Predicate    string `json:"predicate"`
}

Relationship represents a relationship between two entities in search results

type RelationshipEntry

type RelationshipEntry struct {
	ToEntityID string `json:"to_entity_id"`
	Predicate  string `json:"predicate"`
}

RelationshipEntry represents an outgoing relationship from graph-index

type SemanticHit

type SemanticHit struct {
	EntityID string  `json:"entity_id"`
	Score    float64 `json:"score"`
}

SemanticHit represents a search result with semantic similarity score

type Source

type Source struct {
	EntityID    string  `json:"entity_id"`
	CommunityID string  `json:"community_id,omitempty"`
	Relevance   float64 `json:"relevance"`
}

Source represents source attribution for search results

type StaticRouter

type StaticRouter struct {
	// contains filtered or unexported fields
}

StaticRouter routes queries to known graph component subjects. Routing is based on query type string, not runtime discovery.

func NewStaticRouter

func NewStaticRouter(logger *slog.Logger) *StaticRouter

NewStaticRouter creates a router with static routes for all known query types.

func (*StaticRouter) Route

func (r *StaticRouter) Route(queryType string) string

Route returns the NATS subject for a given query type. Returns empty string if the query type is unknown or receiver is nil.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL