Skip to content

Commit 110df05

Browse files
authored
Merge pull request #2102 from weaviate/pr/2090
Add endpoint setting for text2vec-openai and text2vec-morph
2 parents b98d5c6 + c4cf6ee commit 110df05

4 files changed

Lines changed: 94 additions & 0 deletions

File tree

test/collection/test_config.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,21 @@ def test_basic_config():
319319
}
320320
},
321321
),
322+
(
323+
Configure.Vectorizer.text2vec_openai(
324+
vectorize_collection_name=False,
325+
model="ada",
326+
endpoint="/api/v3/embeddings",
327+
),
328+
{
329+
"text2vec-openai": {
330+
"vectorizeClassName": False,
331+
"model": "ada",
332+
"endpoint": "/api/v3/embeddings",
333+
"isAzure": False,
334+
}
335+
},
336+
),
322337
(
323338
Configure.Vectorizer.text2vec_mistral(
324339
vectorize_collection_name=False,
@@ -1759,6 +1774,28 @@ def test_vector_config_flat_pq() -> None:
17591774
}
17601775
},
17611776
),
1777+
(
1778+
[
1779+
Configure.NamedVectors.text2vec_openai(
1780+
name="test",
1781+
source_properties=["prop"],
1782+
endpoint="/api/v3/embeddings",
1783+
)
1784+
],
1785+
{
1786+
"test": {
1787+
"vectorizer": {
1788+
"text2vec-openai": {
1789+
"properties": ["prop"],
1790+
"vectorizeClassName": True,
1791+
"endpoint": "/api/v3/embeddings",
1792+
"isAzure": False,
1793+
}
1794+
},
1795+
"vectorIndexType": "hnsw",
1796+
}
1797+
},
1798+
),
17621799
(
17631800
[Configure.NamedVectors.text2vec_mistral(name="test", source_properties=["prop"])],
17641801
{
@@ -2361,6 +2398,28 @@ def test_config_with_named_vectors(
23612398
}
23622399
},
23632400
),
2401+
(
2402+
[
2403+
Configure.Vectors.text2vec_openai(
2404+
name="test",
2405+
source_properties=["prop"],
2406+
endpoint="/api/v3/embeddings",
2407+
)
2408+
],
2409+
{
2410+
"test": {
2411+
"vectorizer": {
2412+
"text2vec-openai": {
2413+
"properties": ["prop"],
2414+
"vectorizeClassName": True,
2415+
"endpoint": "/api/v3/embeddings",
2416+
"isAzure": False,
2417+
}
2418+
},
2419+
"vectorIndexType": "hnsw",
2420+
}
2421+
},
2422+
),
23642423
(
23652424
[Configure.Vectors.text2vec_mistral(name="test", source_properties=["prop"])],
23662425
{
@@ -2408,6 +2467,27 @@ def test_config_with_named_vectors(
24082467
}
24092468
},
24102469
),
2470+
(
2471+
[
2472+
Configure.Vectors.text2vec_morph(
2473+
name="test",
2474+
source_properties=["prop"],
2475+
endpoint="/api/v3/embeddings",
2476+
)
2477+
],
2478+
{
2479+
"test": {
2480+
"vectorizer": {
2481+
"text2vec-morph": {
2482+
"vectorizeClassName": True,
2483+
"properties": ["prop"],
2484+
"endpoint": "/api/v3/embeddings",
2485+
}
2486+
},
2487+
"vectorIndexType": "hnsw",
2488+
}
2489+
},
2490+
),
24112491
(
24122492
[
24132493
Configure.Vectors.text2vec_google(

weaviate/collections/classes/config_named_vectors.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ def text2vec_openai(
401401
*,
402402
base_url: Optional[AnyHttpUrl] = None,
403403
dimensions: Optional[int] = None,
404+
endpoint: Optional[str] = None,
404405
model: Optional[Union[OpenAIModel, str]] = None,
405406
model_version: Optional[str] = None,
406407
type_: Optional[OpenAIType] = None,
@@ -424,6 +425,7 @@ def text2vec_openai(
424425
vectorize_collection_name: Whether to vectorize the collection name. Defaults to `True`.
425426
base_url: The base URL to use where API requests should go. Defaults to `None`, which uses the server-defined default.
426427
dimensions: Number of dimensions. Applicable to v3 OpenAI models only. Defaults to `None`, which uses the server-defined default.
428+
endpoint: The API path to append to `base_url`, e.g. `/api/v3/embeddings`. Defaults to `None`, which uses the server-defined default.
427429
428430
Raises:
429431
pydantic.ValidationError: If `type_` is not a valid value from the `OpenAIType` type.
@@ -438,6 +440,7 @@ def text2vec_openai(
438440
type_=type_,
439441
vectorizeClassName=vectorize_collection_name,
440442
dimensions=dimensions,
443+
endpoint=endpoint,
441444
),
442445
vector_index_config=vector_index_config,
443446
)

weaviate/collections/classes/config_vectorizers.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ class _Text2VecMorphConfig(_VectorizerConfigCreate):
310310
model: Optional[str]
311311
vectorizeClassName: bool
312312
baseURL: Optional[AnyHttpUrl]
313+
endpoint: Optional[str]
313314

314315
def _to_dict(self) -> Dict[str, Any]:
315316
ret_dict = super()._to_dict()
@@ -336,6 +337,7 @@ class _Text2VecOpenAIConfig(_VectorizerConfigCreate):
336337
)
337338
baseURL: Optional[AnyHttpUrl]
338339
dimensions: Optional[int]
340+
endpoint: Optional[str]
339341
model: Optional[str]
340342
modelVersion: Optional[str]
341343
type_: Optional[OpenAIType]
@@ -1137,6 +1139,7 @@ def text2vec_openai(
11371139
vectorize_collection_name: bool = True,
11381140
base_url: Optional[AnyHttpUrl] = None,
11391141
dimensions: Optional[int] = None,
1142+
endpoint: Optional[str] = None,
11401143
) -> _VectorizerConfigCreate:
11411144
"""Create a `_Text2VecOpenAIConfigCreate` object for use when vectorizing using the `text2vec-openai` model.
11421145
@@ -1150,6 +1153,7 @@ def text2vec_openai(
11501153
vectorize_collection_name: Whether to vectorize the collection name. Defaults to `True`.
11511154
base_url: The base URL to use where API requests should go. Defaults to `None`, which uses the server-defined default.
11521155
dimensions: Number of dimensions. Applicable to v3 OpenAI models only. Defaults to `None`, which uses the server-defined default.
1156+
endpoint: The API path to append to `base_url`, e.g. `/api/v3/embeddings`. Defaults to `None`, which uses the server-defined default.
11531157
11541158
Raises:
11551159
pydantic.ValidationError: If `type_` is not a valid value from the `OpenAIType` type.
@@ -1161,6 +1165,7 @@ def text2vec_openai(
11611165
type_=type_,
11621166
vectorizeClassName=vectorize_collection_name,
11631167
dimensions=dimensions,
1168+
endpoint=endpoint,
11641169
)
11651170

11661171
@staticmethod

weaviate/collections/classes/config_vectors.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,7 @@ def text2vec_morph(
664664
quantizer: Optional[_QuantizerConfigCreate] = None,
665665
base_url: Optional[AnyHttpUrl] = None,
666666
model: Optional[str] = None,
667+
endpoint: Optional[str] = None,
667668
source_properties: Optional[List[str]] = None,
668669
vector_index_config: Optional[_VectorIndexConfigCreate] = None,
669670
vectorize_collection_name: bool = True,
@@ -678,6 +679,7 @@ def text2vec_morph(
678679
quantizer: The quantizer to use for the vector index. If not provided, no quantization will be applied.
679680
base_url: The base URL to use where API requests should go. Defaults to `None`, which uses the server-defined default.
680681
model: The model to use. Defaults to `None`, which uses the server-defined default.
682+
endpoint: The API path to append to `base_url`, e.g. `/api/v3/embeddings`. Defaults to `None`, which uses the server-defined default.
681683
source_properties: Which properties should be included when vectorizing. By default all text properties are included.
682684
vector_index_config: The configuration for Weaviate's vector index. Use `wvc.config.Configure.VectorIndex` to create a vector index configuration. None by default
683685
vectorize_collection_name: Whether to vectorize the collection name. Defaults to `True`.
@@ -688,6 +690,7 @@ def text2vec_morph(
688690
vectorizer=_Text2VecMorphConfig(
689691
baseURL=base_url,
690692
model=model,
693+
endpoint=endpoint,
691694
vectorizeClassName=vectorize_collection_name,
692695
),
693696
vector_index_config=_IndexWrappers.single(vector_index_config, quantizer),
@@ -739,6 +742,7 @@ def text2vec_openai(
739742
quantizer: Optional[_QuantizerConfigCreate] = None,
740743
base_url: Optional[AnyHttpUrl] = None,
741744
dimensions: Optional[int] = None,
745+
endpoint: Optional[str] = None,
742746
model: Optional[Union[OpenAIModel, str]] = None,
743747
model_version: Optional[str] = None,
744748
type_: Optional[OpenAIType] = None,
@@ -756,6 +760,7 @@ def text2vec_openai(
756760
quantizer: The quantizer to use for the vector index. If not provided, no quantization will be applied.
757761
base_url: The base URL to use where API requests should go. Defaults to `None`, which uses the server-defined default.
758762
dimensions: Number of dimensions. Applicable to v3 OpenAI models only. Defaults to `None`, which uses the server-defined default.
763+
endpoint: The API path to append to `base_url`, e.g. `/api/v3/embeddings`. Defaults to `None`, which uses the server-defined default.
759764
model: The model to use. Defaults to `None`, which uses the server-defined default.
760765
model_version: The model version to use. Defaults to `None`, which uses the server-defined default.
761766
type_: The type of model to use. Defaults to `None`, which uses the server-defined default.
@@ -776,6 +781,7 @@ def text2vec_openai(
776781
type_=type_,
777782
vectorizeClassName=vectorize_collection_name,
778783
dimensions=dimensions,
784+
endpoint=endpoint,
779785
),
780786
vector_index_config=_IndexWrappers.single(vector_index_config, quantizer),
781787
)

0 commit comments

Comments
 (0)