Class: Boxcars::VectorStore::Pgvector::BuildFromArray
- Inherits:
-
Object
- Object
- Boxcars::VectorStore::Pgvector::BuildFromArray
- Includes:
- Boxcars::VectorStore
- Defined in:
- lib/boxcars/vector_store/pgvector/build_from_array.rb
Instance Method Summary collapse
-
#call ⇒ Hash
Vector_store: array of hashes with :content, :metadata, and :embedding keys.
-
#initialize(params) ⇒ BuildFromArray
constructor
initialize the vector store with the following parameters:.
Methods included from Boxcars::VectorStore
Constructor Details
#initialize(params) ⇒ BuildFromArray
initialize the vector store with the following parameters:
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 } }
]
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/boxcars/vector_store/pgvector/build_from_array.rb', line 28 def initialize(params) @embedding_tool = params[:embedding_tool] || :openai validate_params(, params[:input_array]) @database_url = params[:database_url] @table_name = params[:table_name] @embedding_column_name = params[:embedding_column_name] @content_column_name = params[:content_column_name] @metadata_column_name = params[:metadata_column_name] @input_array = params[:input_array] @pg_vectors = [] end |
Instance Method Details
#call ⇒ Hash
Returns vector_store: array of hashes with :content, :metadata, and :embedding keys.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/boxcars/vector_store/pgvector/build_from_array.rb', line 44 def call texts = input_array.map { |doc| doc[:content] } vectors = generate_vectors(texts) add_vectors(vectors, input_array) documents = save_vector_store { type: :pgvector, vector_store: documents } end |