1010from redisvl .extensions .cache .embeddings import EmbeddingsCache
1111from redisvl .redis .utils import array_to_buffer
1212from redisvl .schema .fields import VectorDataType
13+ from redisvl .utils .utils import deprecated_argument
1314
1415try :
1516 from PIL .Image import Image
@@ -67,9 +68,11 @@ def check_dtype(cls, dtype):
6768 )
6869 return dtype
6970
71+ @deprecated_argument ("text" , "content" )
7072 def embed (
7173 self ,
72- content : Any ,
74+ content : Any = None ,
75+ text : Any = None ,
7376 preprocess : Optional [Callable ] = None ,
7477 as_buffer : bool = False ,
7578 skip_cache : bool = False ,
@@ -79,6 +82,7 @@ def embed(
7982
8083 Args:
8184 content: The content to convert to a vector embedding
85+ text: The text to convert to a vector embedding (deprecated - use `content` instead)
8286 preprocess: Function to apply to the content before embedding
8387 as_buffer: Return the embedding as a binary buffer instead of a list
8488 skip_cache: Bypass the cache for this request
@@ -91,6 +95,10 @@ def embed(
9195 >>> embedding = text_vectorizer.embed("Hello world")
9296 >>> embedding = image_vectorizer.embed(Image.open("test.png"))
9397 """
98+ content = content or text
99+ if not content :
100+ raise ValueError ("No content provided to embed." )
101+
94102 # Apply preprocessing if provided
95103 if preprocess is not None :
96104 content = preprocess (content )
@@ -128,9 +136,11 @@ def embed(
128136 # Process and return result
129137 return self ._process_embedding (embedding , as_buffer , self .dtype )
130138
139+ @deprecated_argument ("texts" , "contents" )
131140 def embed_many (
132141 self ,
133- contents : List [Any ],
142+ contents : Optional [List [Any ]] = None ,
143+ texts : Optional [List [Any ]] = None ,
134144 preprocess : Optional [Callable ] = None ,
135145 batch_size : int = 10 ,
136146 as_buffer : bool = False ,
@@ -141,6 +151,7 @@ def embed_many(
141151
142152 Args:
143153 contents: List of content to convert to vector embeddings
154+ texts: List of texts to convert to vector embeddings (deprecated - use `contents` instead)
144155 preprocess: Function to apply to each item before embedding
145156 batch_size: Number of items to process in each API call
146157 as_buffer: Return embeddings as binary buffers instead of lists
@@ -153,6 +164,7 @@ def embed_many(
153164 Examples:
154165 >>> embeddings = vectorizer.embed_many(["Hello", "World"], batch_size=2)
155166 """
167+ contents = contents or texts
156168 if not contents :
157169 return []
158170
@@ -186,9 +198,11 @@ def embed_many(
186198 # Process and return results
187199 return [self ._process_embedding (emb , as_buffer , self .dtype ) for emb in results ]
188200
201+ @deprecated_argument ("text" , "content" )
189202 async def aembed (
190203 self ,
191- content : Any ,
204+ content : Any = None ,
205+ text : Any = None ,
192206 preprocess : Optional [Callable ] = None ,
193207 as_buffer : bool = False ,
194208 skip_cache : bool = False ,
@@ -198,6 +212,7 @@ async def aembed(
198212
199213 Args:
200214 content: The content to convert to a vector embedding
215+ text: The text to convert to a vector embedding (deprecated - use `content` instead)
201216 preprocess: Function to apply to the content before embedding
202217 as_buffer: Return the embedding as a binary buffer instead of a list
203218 skip_cache: Bypass the cache for this request
@@ -209,6 +224,10 @@ async def aembed(
209224 Examples:
210225 >>> embedding = await vectorizer.aembed("Hello world")
211226 """
227+ content = content or text
228+ if not content :
229+ raise ValueError ("No content provided to embed." )
230+
212231 # Apply preprocessing if provided
213232 if preprocess is not None :
214233 content = preprocess (content )
@@ -250,9 +269,11 @@ async def aembed(
250269 # Process and return result
251270 return self ._process_embedding (embedding , as_buffer , self .dtype )
252271
272+ @deprecated_argument ("texts" , "contents" )
253273 async def aembed_many (
254274 self ,
255- contents : List [Any ],
275+ contents : Optional [List [Any ]] = None ,
276+ texts : Optional [List [Any ]] = None ,
256277 preprocess : Optional [Callable ] = None ,
257278 batch_size : int = 10 ,
258279 as_buffer : bool = False ,
@@ -263,6 +284,7 @@ async def aembed_many(
263284
264285 Args:
265286 contents: List of content to convert to vector embeddings
287+ texts: List of texts to convert to vector embeddings (deprecated - use `contents` instead)
266288 preprocess: Function to apply to each item before embedding
267289 batch_size: Number of texts to process in each API call
268290 as_buffer: Return embeddings as binary buffers instead of lists
@@ -275,6 +297,7 @@ async def aembed_many(
275297 Examples:
276298 >>> embeddings = await vectorizer.aembed_many(["Hello", "World"], batch_size=2)
277299 """
300+ contents = contents or texts
278301 if not contents :
279302 return []
280303
@@ -308,31 +331,45 @@ async def aembed_many(
308331 # Process and return results
309332 return [self ._process_embedding (emb , as_buffer , self .dtype ) for emb in results ]
310333
311- def _embed (self , content : Any , ** kwargs ) -> List [float ]:
334+ @deprecated_argument ("text" , "content" )
335+ def _embed (self , text : Any = "" , content : Any = "" , ** kwargs ) -> List [float ]:
312336 """Generate a vector embedding for a single item."""
313337 raise NotImplementedError
314338
339+ @deprecated_argument ("texts" , "contents" )
315340 def _embed_many (
316- self , contents : List [Any ], batch_size : int = 10 , ** kwargs
341+ self ,
342+ contents : Optional [List [Any ]] = None ,
343+ texts : Optional [List [Any ]] = None ,
344+ batch_size : int = 10 ,
345+ ** kwargs ,
317346 ) -> List [List [float ]]:
318347 """Generate vector embeddings for a batch of items."""
319348 raise NotImplementedError
320349
321- async def _aembed (self , content : Any , ** kwargs ) -> List [float ]:
350+ @deprecated_argument ("text" , "content" )
351+ async def _aembed (self , content : Any = "" , text : Any = "" , ** kwargs ) -> List [float ]:
322352 """Asynchronously generate a vector embedding for a single item."""
323353 logger .warning (
324354 "This vectorizer has no async embed method. Falling back to sync."
325355 )
326- return self ._embed (content , ** kwargs )
356+ return self ._embed (content = content or text , ** kwargs )
327357
358+ @deprecated_argument ("texts" , "contents" )
328359 async def _aembed_many (
329- self , contents : List [Any ], batch_size : int = 10 , ** kwargs
360+ self ,
361+ contents : Optional [List [Any ]] = None ,
362+ texts : Optional [List [Any ]] = None ,
363+ batch_size : int = 10 ,
364+ ** kwargs ,
330365 ) -> List [List [float ]]:
331366 """Asynchronously generate vector embeddings for a batch of items."""
332367 logger .warning (
333368 "This vectorizer has no async embed_many method. Falling back to sync."
334369 )
335- return self ._embed_many (contents , batch_size , ** kwargs )
370+ return self ._embed_many (
371+ contents = contents or texts , batch_size = batch_size , ** kwargs
372+ )
336373
337374 def _get_from_cache_batch (
338375 self , contents : List [Any ], skip_cache : bool
0 commit comments