Skip to content

Commit efde474

Browse files
committed
add multi2multivec-weaviate vectorizer
1 parent 2e6c428 commit efde474

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

weaviate/collections/classes/config_vectorizers.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ class Vectorizers(str, Enum):
131131
MULTI2VEC_COHERE = "multi2vec-cohere"
132132
MULTI2VEC_JINAAI = "multi2vec-jinaai"
133133
MULTI2MULTI_JINAAI = "multi2multivec-jinaai"
134+
MULTI2MULTI_WEAVIATE = "multi2multivec-weaviate"
134135
MULTI2VEC_BIND = "multi2vec-bind"
135136
MULTI2VEC_PALM = "multi2vec-palm" # change to google once 1.27 is the lowest supported version
136137
MULTI2VEC_VOYAGEAI = "multi2vec-voyageai"
@@ -507,6 +508,20 @@ def _to_dict(self) -> Dict[str, Any]:
507508
return ret_dict
508509

509510

511+
class _Multi2MultiVecWeaviateConfig(_Multi2VecBase):
512+
vectorizer: Union[Vectorizers, _EnumLikeStr] = Field(
513+
default=Vectorizers.MULTI2MULTI_WEAVIATE, frozen=True, exclude=True
514+
)
515+
baseURL: Optional[AnyHttpUrl]
516+
model: Optional[str]
517+
518+
def _to_dict(self) -> Dict[str, Any]:
519+
ret_dict = super()._to_dict()
520+
if self.baseURL is not None:
521+
ret_dict["baseURL"] = self.baseURL.unicode_string()
522+
return ret_dict
523+
524+
510525
class _Multi2VecClipConfig(_Multi2VecBase):
511526
vectorizer: Union[Vectorizers, _EnumLikeStr] = Field(
512527
default=Vectorizers.MULTI2VEC_CLIP, frozen=True, exclude=True

weaviate/collections/classes/config_vectors.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
_Img2VecNeuralConfig,
4141
_map_multi2vec_fields,
4242
_Multi2MultiVecJinaConfig,
43+
_Multi2MultiVecWeaviateConfig,
4344
_Multi2VecAWSConfig,
4445
_Multi2VecBindConfig,
4546
_Multi2VecClipConfig,
@@ -287,6 +288,47 @@ def multi2vec_jinaai(
287288
),
288289
)
289290

291+
@staticmethod
292+
def multi2vec_weaviate(
293+
*,
294+
name: Optional[str] = None,
295+
encoding: Optional[_MultiVectorEncodingConfigCreate] = None,
296+
quantizer: Optional[_QuantizerConfigCreate] = None,
297+
base_url: Optional[AnyHttpUrl] = None,
298+
image_fields: Optional[Union[List[str], List[Multi2VecField]]] = None,
299+
model: Optional[Union[JinaMultimodalModel, str]] = None,
300+
multi_vector_config: Optional[_MultiVectorConfigCreate] = None,
301+
vector_index_config: Optional[_VectorIndexConfigCreate] = None,
302+
) -> _VectorConfigCreate:
303+
"""Create a vector using the `multi2multivec-weaviate` module.
304+
305+
See the [documentation](TODO)
306+
for detailed usage.
307+
308+
Args:
309+
name: The name of the vector.
310+
encoding: The type of multi-vector encoding to use in the vector index. Defaults to `None`, which uses the server-defined default.
311+
quantizer: The quantizer to use for the vector index. If not provided, no quantization will be applied.
312+
base_url: The base URL to use where API requests should go. Defaults to `None`, which uses the server-defined default.
313+
image_fields: The image fields to use in vectorization.
314+
model: The model to use. Defaults to `None`, which uses the server-defined default.
315+
multi_vector_config: The configuration for the multi-vector index. Use `wvc.config.Configure.VectorIndex.MultiVector` to create a multi-vector configuration. None by default
316+
vector_index_config: The configuration for Weaviate's vector index. Use `wvc.config.Configure.VectorIndex` to create a vector index configuration. None by default
317+
"""
318+
return _VectorConfigCreate(
319+
name=name,
320+
vectorizer=_Multi2MultiVecWeaviateConfig(
321+
baseURL=base_url,
322+
model=model,
323+
imageFields=_map_multi2vec_fields(image_fields),
324+
# TODO: figure out how to workaround not supporting text fields
325+
textFields=_map_multi2vec_fields(None),
326+
),
327+
vector_index_config=_IndexWrappers.multi(
328+
vector_index_config, quantizer, multi_vector_config, encoding
329+
),
330+
)
331+
290332

291333
class _Vectors:
292334
@staticmethod

0 commit comments

Comments
 (0)