-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
566: Similar search added (#546) r=brunoocasali a=andre-m-dev # Pull Request ## Related issue Fixes #546 ## What does this PR do? - Get similar documents ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Co-authored-by: Andre <> Co-authored-by: André <[email protected]>
- Loading branch information
Showing
4 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe 'MeiliSearch::Index - Search for similar documents' do | ||
let(:new_index) { client.index('similar_test_search') } | ||
|
||
before do | ||
client.create_index('similar_test_search').await | ||
end | ||
|
||
it 'requires document_id parameter' do | ||
expect { new_index.search_similar_documents }.to raise_error ArgumentError | ||
end | ||
|
||
it 'does a search for similar documents' do | ||
enable_vector_store(true) | ||
|
||
documents = [ | ||
{ | ||
title: 'Shazam!', | ||
release_year: 2019, | ||
id: '287947', | ||
_vectors: { 'manual' => [0.8, 0.4, -0.5] } | ||
}, | ||
{ | ||
title: 'Captain Marvel', | ||
release_year: 2019, | ||
id: '299537', | ||
_vectors: { 'manual' => [0.6, 0.8, -0.2] } | ||
}, | ||
{ | ||
title: 'How to Train Your Dragon: The Hidden World', | ||
release_year: 2019, | ||
id: '166428', | ||
_vectors: { 'manual' => [0.7, 0.7, -0.4] } | ||
} | ||
] | ||
|
||
new_index.update_settings( | ||
embedders: { | ||
'manual' => { | ||
source: 'userProvided', | ||
dimensions: 3 | ||
} | ||
} | ||
).await | ||
|
||
new_index.add_documents(documents).await | ||
|
||
response = new_index.search_similar_documents('287947') | ||
|
||
expect(response['hits']).not_to be_empty | ||
expect(response['estimatedTotalHits']).not_to be_nil | ||
end | ||
end |