Skip to content
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
35 changes: 35 additions & 0 deletions weaviate/collections/classes/config_named_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
_Text2VecWeaviateConfig,
_VectorizerConfigCreate,
_VectorizerCustomConfig,
_Text2VecModel2VecConfig,
)

from ...warnings import _Warnings
Expand Down Expand Up @@ -1072,6 +1073,7 @@ def text2vec_google_aistudio(
def text2vec_transformers(
name: str,
*,
dimensions: Optional[int] = None,
pooling_strategy: Literal["masked_mean", "cls"] = "masked_mean",
inference_url: Optional[str] = None,
passage_inference_url: Optional[str] = None,
Expand All @@ -1087,6 +1089,7 @@ def text2vec_transformers(

Args:
name: The name of the named vector.
dimensions: The number of dimensions for the generated embeddings. Defaults to `None`, which uses the server-defined default.
source_properties: Which properties should be included when vectorizing. By default all text properties are included.
vector_index_config: The configuration for Weaviate's vector index. Use wvc.config.Configure.VectorIndex to create a vector index configuration. None by default
vectorize_collection_name: Whether to vectorize the collection name. Defaults to `True`.
Expand All @@ -1099,6 +1102,7 @@ def text2vec_transformers(
name=name,
source_properties=source_properties,
vectorizer=_Text2VecTransformersConfig(
dimensions=dimensions,
poolingStrategy=pooling_strategy,
vectorizeClassName=vectorize_collection_name,
inferenceUrl=inference_url,
Expand Down Expand Up @@ -1287,6 +1291,37 @@ def text2vec_nvidia(
vector_index_config=vector_index_config,
)

@staticmethod
def text2vec_model2vec(
name: str,
*,
source_properties: Optional[List[str]] = None,
vector_index_config: Optional[_VectorIndexConfigCreate] = None,
vectorize_collection_name: bool = True,
inference_url: Optional[str] = None,
) -> _NamedVectorConfigCreate:
"""Create a named vector using the `text2vec-model2vec` model.

See the [documentation](https://weaviate.io/developers/weaviate/model-providers/model2vec/embeddings)
for detailed usage.

Args:
name: The name of the named vector.
source_properties: Which properties should be included when vectorizing. By default all text properties are included.
vector_index_config: The configuration for Weaviate's vector index. Use wvc.config.Configure.VectorIndex to create a vector index configuration. None by default
vectorize_collection_name: Whether to vectorize the collection name. Defaults to `True`.
inference_url: The inference url to use where API requests should go. Defaults to `None`, which uses the server-defined default.
"""
return _NamedVectorConfigCreate(
name=name,
source_properties=source_properties,
vectorizer=_Text2VecModel2VecConfig(
vectorizeClassName=vectorize_collection_name,
inferenceUrl=inference_url,
),
vector_index_config=vector_index_config,
)


class _NamedVectorsUpdate:
@staticmethod
Expand Down
25 changes: 24 additions & 1 deletion weaviate/collections/classes/config_vectorizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class _Text2VecContextionaryConfig(_VectorizerConfigCreate):
vectorizeClassName: bool


class _Text2VecModel2Vec(_VectorizerConfigCreate):
class _Text2VecModel2VecConfig(_VectorizerConfigCreate):
vectorizer: Union[Vectorizers, _EnumLikeStr] = Field(
default=Vectorizers.TEXT2VEC_MODEL2VEC, frozen=True, exclude=True
)
Expand Down Expand Up @@ -1278,6 +1278,7 @@ def multi2vec_google(
@staticmethod
def text2vec_transformers(
pooling_strategy: Literal["masked_mean", "cls"] = "masked_mean",
dimensions: Optional[int] = None,
vectorize_collection_name: bool = True,
inference_url: Optional[str] = None,
passage_inference_url: Optional[str] = None,
Expand All @@ -1290,6 +1291,7 @@ def text2vec_transformers(

Args:
pooling_strategy: The pooling strategy to use. Defaults to `masked_mean`.
dimensions: The number of dimensions for the generated embeddings. Defaults to `None`, which uses the server-defined default.
vectorize_collection_name: Whether to vectorize the collection name. Defaults to `True`.
inference_url: The inference url to use where API requests should go. You can use either this OR passage/query_inference_url. Defaults to `None`, which uses the server-defined default.
passage_inference_url: The inference url to use where passage API requests should go. You can use either this and query_inference_url OR inference_url. Defaults to `None`, which uses the server-defined default.
Expand All @@ -1300,6 +1302,7 @@ def text2vec_transformers(
"""
return _Text2VecTransformersConfig(
poolingStrategy=pooling_strategy,
dimensions=dimensions,
vectorizeClassName=vectorize_collection_name,
inferenceUrl=inference_url,
passageInferenceUrl=passage_inference_url,
Expand Down Expand Up @@ -1438,3 +1441,23 @@ def text2vec_nvidia(
truncate=truncate,
vectorizeClassName=vectorize_collection_name,
)

@staticmethod
def text2vec_model2vec(
*,
inference_url: Optional[str] = None,
vectorize_collection_name: bool = True,
) -> _VectorizerConfigCreate:
"""Create a `_Text2VecModel2VecConfigCreate` object for use when vectorizing using the `text2vec-model2vec` model.

See the [documentation](https://weaviate.io/developers/weaviate/model-providers/model2vec/embeddings)
for detailed usage.

Args:
vectorize_collection_name: Whether to vectorize the collection name. Defaults to `True`.
inference_url: The inference url to use where API requests should go. Defaults to `None`, which uses the server-defined default.
"""
return _Text2VecModel2VecConfig(
vectorizeClassName=vectorize_collection_name,
inferenceUrl=inference_url,
)
4 changes: 2 additions & 2 deletions weaviate/collections/classes/config_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@
_Text2VecHuggingFaceConfig,
_Text2VecJinaConfig,
_Text2VecMistralConfig,
_Text2VecModel2Vec,
_Text2VecNvidiaConfig,
_Text2VecOllamaConfig,
_Text2VecOpenAIConfig,
_Text2VecTransformersConfig,
_Text2VecVoyageConfig,
_Text2VecWeaviateConfig,
_Text2VecModel2VecConfig,
_VectorizerConfigCreate,
_VectorizerCustomConfig,
)
Expand Down Expand Up @@ -480,7 +480,7 @@ def text2vec_model2vec(
return _VectorConfigCreate(
name=name,
source_properties=source_properties,
vectorizer=_Text2VecModel2Vec(
vectorizer=_Text2VecModel2VecConfig(
vectorizeClassName=vectorize_collection_name,
inferenceUrl=inference_url,
),
Expand Down