Class: Boxcars::VectorSearch

Inherits:
Object
  • Object
show all
Defined in:
lib/boxcars/vector_search.rb

Overview

For Boxcars that use an engine to do their work.

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ VectorSearch

initialize the vector search with the following parameters: example: {

type: :in_memory,
vector_store: [
  Boxcars::VectorStore::Document.new(
    content: "hello",
    embedding: [0.1, 0.2, 0.3],
    metadata: { a: 1 }
  )
]

}

Parameters:

  • params (Hash)

    A Hash containing the initial configuration.

Options Hash (params):

  • :vector_documents (Hash)

    The vector documents to search.



21
22
23
24
25
26
# File 'lib/boxcars/vector_search.rb', line 21

def initialize(params)
  @vector_documents = params[:vector_documents]
  @embedding_tool = params[:embedding_tool] || :openai
  @vector_search_instance = vector_search_instance
  @openai_connection = params[:openai_connection] || default_connection(openai_access_token: params[:openai_access_token])
end

Instance Method Details

#call(query:, count: 1) ⇒ Array

Returns array of hashes with :document and :distance keys.

Examples:

[
  {
    document: Boxcars::VectorStore::Document.new(
      content: "hello",
      embedding: [0.1, 0.2, 0.3],
      metadata: { a: 1 }
    ),
    distance: 0.1
  }
]

Parameters:

  • query (String)

    The query to search for.

  • count (Integer) (defaults to: 1)

    The number of results to return.

Returns:

  • (Array)

    array of hashes with :document and :distance keys



42
43
44
45
46
# File 'lib/boxcars/vector_search.rb', line 42

def call(query:, count: 1)
  validate_query(query)
  query_vector = convert_query_to_vector(query)
  @vector_search_instance.call(query_vector: query_vector, count: count)
end