Class: Boxcars::VectorStore::InMemory::BuildFromArray

Inherits:
Object
  • Object
show all
Includes:
Boxcars::VectorStore
Defined in:
lib/boxcars/vector_store/in_memory/build_from_array.rb

Instance Method Summary collapse

Methods included from Boxcars::VectorStore

included

Constructor Details

#initialize(embedding_tool: :openai, input_array: nil) ⇒ Hash

each hash item should have content and metadata [

{ content: "hello", metadata: { a: 1 } },
{ content: "hi", metadata: { a: 1 } },
{ content: "bye", metadata: { a: 1 } },
{ content: "what's this", metadata: { a: 1 } }

]

Parameters:

  • embedding_tool (Symbol) (defaults to: :openai)

    :openai or other embedding tools

  • input_array (Array) (defaults to: nil)

    array of hashes with :content and :metadata keys



19
20
21
22
23
24
# File 'lib/boxcars/vector_store/in_memory/build_from_array.rb', line 19

def initialize(embedding_tool: :openai, input_array: nil)
  validate_params(embedding_tool, input_array)
  @embedding_tool = embedding_tool
  @input_array = input_array
  @memory_vectors = []
end

Instance Method Details

#callHash

Returns vector_store: array of Inventor::VectorStore::Document.

Returns:

  • (Hash)

    vector_store: array of Inventor::VectorStore::Document



27
28
29
30
31
32
33
34
35
36
# File 'lib/boxcars/vector_store/in_memory/build_from_array.rb', line 27

def call
  texts = input_array.map { |doc| doc[:content] }
  vectors = generate_vectors(texts)
  add_vectors(vectors, input_array)

  {
    type: :in_memory,
    vector_store: memory_vectors
  }
end