Module: KairosMcp::VectorSearch

Defined in:
lib/kairos_mcp/vector_search/base.rb,
lib/kairos_mcp/vector_search/provider.rb,
lib/kairos_mcp/vector_search/fallback_search.rb,
lib/kairos_mcp/vector_search/semantic_search.rb

Defined Under Namespace

Classes: Base, FallbackSearch, SemanticSearch

Class Method Summary collapse

Class Method Details

.available?Boolean

Check if semantic search gems are available

Returns:

  • (Boolean)

    true if hnswlib and informers are installed



23
24
25
26
27
# File 'lib/kairos_mcp/vector_search/provider.rb', line 23

def available?
  return @available if defined?(@available)

  @available = check_gems_available
end

.check_gems_availableBoolean

Check gems without caching (useful for testing)

Returns:

  • (Boolean)


32
33
34
35
36
37
38
# File 'lib/kairos_mcp/vector_search/provider.rb', line 32

def check_gems_available
  require 'hnswlib'
  require 'informers'
  true
rescue LoadError
  false
end

.create(index_path: nil, dimension: 384, model: nil, force_fallback: false) ⇒ Base

Create a vector search instance

Parameters:

  • index_path (String) (defaults to: nil)

    Path to store/load index files

  • dimension (Integer) (defaults to: 384)

    Embedding dimension (default: 384 for MiniLM)

  • model (String) (defaults to: nil)

    Sentence transformer model name

  • force_fallback (Boolean) (defaults to: false)

    Force fallback search even if gems available

Returns:

  • (Base)

    A vector search instance



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/kairos_mcp/vector_search/provider.rb', line 52

def create(index_path: nil, dimension: 384, model: nil, force_fallback: false)
  if !force_fallback && available?
    require_relative 'semantic_search'
    SemanticSearch.new(
      index_path: index_path || default_index_path,
      dimension: dimension,
      model: model || SemanticSearch::DEFAULT_MODEL
    )
  else
    require_relative 'fallback_search'
    FallbackSearch.new
  end
end

.reset_availability!Object

Reset the availability cache (for testing)



41
42
43
# File 'lib/kairos_mcp/vector_search/provider.rb', line 41

def reset_availability!
  remove_instance_variable(:@available) if defined?(@available)
end

.statusHash

Get status information about vector search

Returns:

  • (Hash)

    Status including availability and configuration



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/kairos_mcp/vector_search/provider.rb', line 69

def status
  {
    semantic_available: available?,
    gems: {
      hnswlib: gem_version('hnswlib'),
      informers: gem_version('informers')
    },
    default_model: available? ? 'sentence-transformers/all-MiniLM-L6-v2' : nil,
    default_dimension: 384
  }
end