Class: Boxcars::VectorStore::Hnswlib::SaveToHnswlib
- Inherits:
-
Object
- Object
- Boxcars::VectorStore::Hnswlib::SaveToHnswlib
- Includes:
- Boxcars::VectorStore
- Defined in:
- lib/boxcars/vector_store/hnswlib/save_to_hnswlib.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(hnsw_vectors_array) ⇒ SaveToHnswlib
constructor
A new instance of SaveToHnswlib.
Methods included from Boxcars::VectorStore
Constructor Details
#initialize(hnsw_vectors_array) ⇒ SaveToHnswlib
Returns a new instance of SaveToHnswlib.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/boxcars/vector_store/hnswlib/save_to_hnswlib.rb', line 16 def initialize(hnsw_vectors_array) @metadata = hnsw_vectors_array&.first&. validate_params(hnsw_vectors_array, ) @vectors = hnsw_vectors_array @index_file_path = [:index_file_path] @json_doc_file_path = [:json_doc_file_path] || @index_file_path.gsub(/\.bin$/, '.json') @metric = [:metric] || "l2" @dim = [:dim] @max_item = [:max_item] || 10000 @index = ::Hnswlib::HierarchicalNSW.new( space: @metric, dim: @dim ) @index.init_index(max_elements: @max_item) end |
Instance Method Details
#call ⇒ Object
35 36 37 38 |
# File 'lib/boxcars/vector_store/hnswlib/save_to_hnswlib.rb', line 35 def call document_texts = add_vectors_to_index write_files(index, document_texts) end |