Class: Boxcars::VectorSearch
- Inherits:
-
Object
- Object
- Boxcars::VectorSearch
- Defined in:
- lib/boxcars/vector_search.rb
Overview
For Boxcars that use an engine to do their work.
Instance Method Summary collapse
-
#call(query:, count: 1) ⇒ Array
Array of hashes with :document and :distance keys.
-
#initialize(params) ⇒ VectorSearch
constructor
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 } ) ] }.
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 }
)
]
}
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.
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 |