Skip to content

Commit 884f46d

Browse files
Merge #592
592: Support embedders API r=curquiza a=ellnix # Pull Request ## Related issue Fixes #590 Co-authored-by: ellnix <[email protected]>
2 parents 55a576d + f68737b commit 884f46d

File tree

4 files changed

+74
-4
lines changed

4 files changed

+74
-4
lines changed

.code-samples.meilisearch.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,19 @@ get_all_batches_1: |-
689689
client.batches
690690
get_batch_1: |-
691691
client.batch(BATCH_UID)
692+
get_embedders_1: |-
693+
client.index('INDEX_NAME').embedders
694+
update_embedders_1: |-
695+
client.index('INDEX_NAME').update_embedders(
696+
default: {
697+
source: 'openAi',
698+
api_key: 'anOpenAiApiKey',
699+
model: 'text-embedding-3-small',
700+
document_template: "A document titled '{{doc.title}}' whose description starts with {{doc.overview|truncatewords: 20}}"
701+
}
702+
)
703+
reset_embedders_1: |-
704+
client.index('INDEX_NAME').reset_embedders
692705
distinct_attribute_guide_filterable_1: |-
693706
client.index('products').update_filterable_attributes([
694707
'product_id',

.rubocop_todo.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2025-01-08 15:54:24 UTC using RuboCop version 1.69.2.
3+
# on 2025-01-10 14:26:27 UTC using RuboCop version 1.69.2.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 66
9+
# Offense count: 67
1010
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
1111
# AllowedMethods: refine
1212
Metrics/BlockLength:
13-
Max: 670
13+
Max: 702
1414

1515
# Offense count: 4
1616
# Configuration parameters: CountComments, CountAsOne.
1717
Metrics/ClassLength:
18-
Max: 470
18+
Max: 480
1919

2020
# Offense count: 1
2121
# Configuration parameters: Max, CountKeywordArgs.

lib/meilisearch/index.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,5 +673,21 @@ def update_prefix_search(new_prefix_search_setting)
673673
def reset_prefix_search
674674
http_delete("/indexes/#{@uid}/settings/prefix-search")
675675
end
676+
677+
### SETTINGS - EMBEDDERS
678+
679+
def embedders
680+
http_get("/indexes/#{@uid}/settings/embedders")
681+
end
682+
683+
def update_embedders(new_embedders)
684+
new_embedders = Utils.transform_attributes(new_embedders)
685+
686+
http_patch("/indexes/#{@uid}/settings/embedders", new_embedders)
687+
end
688+
689+
def reset_embedders
690+
http_delete("/indexes/#{@uid}/settings/embedders")
691+
end
676692
end
677693
end

spec/meilisearch/index/settings_spec.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,4 +865,45 @@
865865
expect(index.prefix_search).to eq(default_prefix_search)
866866
end
867867
end
868+
869+
context 'on embedders' do
870+
let(:index) { client.index(uid) }
871+
let(:default_embedders) { nil }
872+
873+
before { client.create_index(uid).await }
874+
before { enable_vector_store(true) }
875+
876+
it '#embedders gets default value' do
877+
expect(index.embedders).to eq(default_embedders)
878+
end
879+
880+
it '#update_embedders updates default value' do
881+
update_task = index.update_embedders(
882+
custom: {
883+
source: 'userProvided',
884+
dimensions: 3
885+
}
886+
)
887+
client.wait_for_task(update_task['taskUid'])
888+
889+
expect(index.embedders).to have_key('custom')
890+
end
891+
892+
it '#reset_embedders resets embedders to nil' do
893+
update_task = index.update_embedders(
894+
custom: {
895+
source: 'userProvided',
896+
dimensions: 3
897+
}
898+
)
899+
client.wait_for_task(update_task['taskUid'])
900+
901+
expect(index.embedders).to have_key('custom')
902+
903+
reset_task = index.reset_embedders
904+
client.wait_for_task(reset_task['taskUid'])
905+
906+
expect(index.embedders).to eq(default_embedders)
907+
end
908+
end
868909
end

0 commit comments

Comments
 (0)