Skip to content

Commit 4298f6f

Browse files
authored
vectorstores: add WithEndpoint option for Azure AI Search (tmc#1308)
1 parent e2368a2 commit 4298f6f

2 files changed

Lines changed: 12 additions & 20 deletions

File tree

vectorstores/azureaisearch/azureaisearch_httprr_test.go

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,11 @@ func TestStoreHTTPRR_CreateIndex(t *testing.T) {
4646
apiKey = envKey
4747
}
4848

49-
// Set endpoint via environment variable
50-
os.Setenv("AZURE_AI_SEARCH_ENDPOINT", endpoint)
51-
defer os.Unsetenv("AZURE_AI_SEARCH_ENDPOINT")
52-
5349
store, err := New(
5450
WithAPIKey(apiKey),
5551
WithEmbedder(&mockEmbedder{}),
5652
WithHTTPClient(rr.Client()),
53+
WithEndpoint(endpoint),
5754
)
5855
require.NoError(t, err)
5956

@@ -81,14 +78,11 @@ func TestStoreHTTPRR_AddDocuments(t *testing.T) {
8178
apiKey = envKey
8279
}
8380

84-
// Set endpoint via environment variable
85-
os.Setenv("AZURE_AI_SEARCH_ENDPOINT", endpoint)
86-
defer os.Unsetenv("AZURE_AI_SEARCH_ENDPOINT")
87-
8881
store, err := New(
8982
WithAPIKey(apiKey),
9083
WithEmbedder(&mockEmbedder{}),
9184
WithHTTPClient(rr.Client()),
85+
WithEndpoint(endpoint),
9286
)
9387
require.NoError(t, err)
9488

@@ -133,14 +127,11 @@ func TestStoreHTTPRR_SimilaritySearch(t *testing.T) {
133127
apiKey = envKey
134128
}
135129

136-
// Set endpoint via environment variable
137-
os.Setenv("AZURE_AI_SEARCH_ENDPOINT", endpoint)
138-
defer os.Unsetenv("AZURE_AI_SEARCH_ENDPOINT")
139-
140130
store, err := New(
141131
WithAPIKey(apiKey),
142132
WithEmbedder(&mockEmbedder{}),
143133
WithHTTPClient(rr.Client()),
134+
WithEndpoint(endpoint),
144135
)
145136
require.NoError(t, err)
146137

@@ -169,14 +160,11 @@ func TestStoreHTTPRR_DeleteIndex(t *testing.T) {
169160
apiKey = envKey
170161
}
171162

172-
// Set endpoint via environment variable
173-
os.Setenv("AZURE_AI_SEARCH_ENDPOINT", endpoint)
174-
defer os.Unsetenv("AZURE_AI_SEARCH_ENDPOINT")
175-
176163
store, err := New(
177164
WithAPIKey(apiKey),
178165
WithEmbedder(&mockEmbedder{}),
179166
WithHTTPClient(rr.Client()),
167+
WithEndpoint(endpoint),
180168
)
181169
require.NoError(t, err)
182170

@@ -203,14 +191,11 @@ func TestStoreHTTPRR_ListIndexes(t *testing.T) {
203191
apiKey = envKey
204192
}
205193

206-
// Set endpoint via environment variable
207-
os.Setenv("AZURE_AI_SEARCH_ENDPOINT", endpoint)
208-
defer os.Unsetenv("AZURE_AI_SEARCH_ENDPOINT")
209-
210194
store, err := New(
211195
WithAPIKey(apiKey),
212196
WithEmbedder(&mockEmbedder{}),
213197
WithHTTPClient(rr.Client()),
198+
WithEndpoint(endpoint),
214199
)
215200
require.NoError(t, err)
216201

vectorstores/azureaisearch/options.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ func WithAPIKey(azureAISearchAPIKey string) Option {
6868
}
6969
}
7070

71+
// WithEndpoint is an option for setting the azure AI search endpoint.
72+
func WithEndpoint(endpoint string) Option {
73+
return func(s *Store) {
74+
s.azureAISearchEndpoint = strings.TrimSuffix(endpoint, "/")
75+
}
76+
}
77+
7178
func applyClientOptions(s *Store, opts ...Option) error {
7279
for _, opt := range opts {
7380
opt(s)

0 commit comments

Comments
 (0)