Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EXPERIMENTAL] Vector Store #478

Merged
merged 1 commit into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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