Class: Noiseless::AST::Hybrid

Inherits:
Node
  • Object
show all
Defined in:
lib/noiseless/ast/hybrid.rb

Overview

Hybrid search node combining text and vector search Supports weighted combination of BM25 text scores and kNN vector scores

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#to_h

Constructor Details

#initialize(text_query, vector, text_weight: 0.5, vector_weight: 0.5) ⇒ Hybrid

Returns a new instance of Hybrid.

Parameters:

  • text_query (String)

    The text query for BM25 matching

  • vector (AST::Vector)

    The vector search node

  • text_weight (Float) (defaults to: 0.5)

    Weight for text search score (0.0-1.0)

  • vector_weight (Float) (defaults to: 0.5)

    Weight for vector search score (0.0-1.0)



14
15
16
17
18
19
20
# File 'lib/noiseless/ast/hybrid.rb', line 14

def initialize(text_query, vector, text_weight: 0.5, vector_weight: 0.5)
  super()
  @text_query = text_query
  @vector = vector
  @text_weight = text_weight
  @vector_weight = vector_weight
end

Instance Attribute Details

#text_queryObject (readonly)

Returns the value of attribute text_query.



8
9
10
# File 'lib/noiseless/ast/hybrid.rb', line 8

def text_query
  @text_query
end

#text_weightObject (readonly)

Returns the value of attribute text_weight.



8
9
10
# File 'lib/noiseless/ast/hybrid.rb', line 8

def text_weight
  @text_weight
end

#vectorObject (readonly)

Returns the value of attribute vector.



8
9
10
# File 'lib/noiseless/ast/hybrid.rb', line 8

def vector
  @vector
end

#vector_weightObject (readonly)

Returns the value of attribute vector_weight.



8
9
10
# File 'lib/noiseless/ast/hybrid.rb', line 8

def vector_weight
  @vector_weight
end

Instance Method Details

#balanced?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/noiseless/ast/hybrid.rb', line 22

def balanced?
  @text_weight == @vector_weight
end

#text_dominant?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/noiseless/ast/hybrid.rb', line 26

def text_dominant?
  @text_weight > @vector_weight
end

#vector_dominant?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/noiseless/ast/hybrid.rb', line 30

def vector_dominant?
  @vector_weight > @text_weight
end