Skip to content

Commit

Permalink
Added [v1.3] [EXPERIMENTAL] Vector Store #457
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre committed Aug 20, 2023
1 parent 11f0edb commit f590d3d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
15 changes: 15 additions & 0 deletions spec/meilisearch/index/documents_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,21 @@
client.wait_for_task(task['taskUid'])
expect(index.task(task['taskUid'])['status']).to eq('failed')
end

it 'allows the user to store vectors' do
enable_vector_store(true)

new_doc = { objectId: 123, _vectors: [0.1, 0.2, 0.3] }
client.create_index!('vector_test')
new_index = client.index('vector_test')
expect do
new_index.add_documents!(new_doc)
end.to(change { new_index.documents['results'].length }.by(1))
expect(new_index.document(123)).to have_key('_vectors')
expect(new_index.document(123)['_vectors']).to be_a(Array)
expect(new_index.document(123)['_vectors'].first).to be_a(Float)
expect(new_index.document(123)['_vectors'].first).to eq(0.1)
end
end

describe 'accessing documents' do
Expand Down
19 changes: 19 additions & 0 deletions spec/meilisearch/index/search/vector_search.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

RSpec.describe 'MeiliSearch::Index - Vector search' do
it 'does a basic search' do
enable_vector_store(true)

documents = [
{ objectId: 0, _vectors: [0, 0.8, -0.2], title: 'Across The Universe' },
{ objectId: 1, _vectors: [1, -0.2, 0], title: 'All Things Must Pass' },
{ objectId: 2, _vectors: [0.5, 3, 1], title: 'And Your Bird Can Sing' }
]

client.create_index!('vector_test_search')
new_index = client.index('vector_test_search')
new_index.add_documents!(documents)

expect(new_index.search('q', vector: [0, 1, 2])['hits']).not_to be_empty
end
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,5 @@
config.include TaskHelpers
config.include ExceptionsHelpers
config.include KeysHelpers
config.include ExperimentalFeatureHelpers
end
14 changes: 13 additions & 1 deletion spec/support/experimental_feature_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,24 @@

module ExperimentalFeatureHelpers
def enable_score_details(toggle)
configure_feature('scoreDetails', toggle)
end

def enable_vector_store(toggle)
configure_feature('vectorStore', toggle)
end

private

# @param [String] attribute_to_toggle
# @param [Boolean] toggle
def configure_feature(attribute_to_toggle, toggle)
uri = URI("http://#{ENV.fetch('MEILISEARCH_URL', 'localhost')}")
uri.path = '/experimental-features'
uri.port = ENV.fetch('MEILISEARCH_PORT', '7700')

req = Net::HTTP::Patch.new(uri)
req.body = { scoreDetails: toggle }.to_json
req.body = { attribute_to_toggle => toggle }.to_json
req.content_type = 'application/json'
req['Authorization'] = "Bearer #{MASTER_KEY}"

Expand Down

0 comments on commit f590d3d

Please sign in to comment.