EmbeddingsLambda(
self,
func: EmbeddingsFunc | AEmbeddingsFunc,
)| Name | Type | Description |
|---|---|---|
func* | EmbeddingsFunc | AEmbeddingsFunc | Function that converts text to embeddings. Can be sync or async. If async, it will be used for async operations, but sync operations will raise an error. If sync, it will be used for both sync and async operations. |
| Name | Type |
|---|---|
| func | EmbeddingsFunc | AEmbeddingsFunc |
Wrapper to convert embedding functions into LangChain's Embeddings interface.
This class allows arbitrary embedding functions to be used with LangChain-compatible tools. It supports both synchronous and asynchronous operations, and can handle:
The embedding functions should convert text into fixed-dimensional vectors that capture the semantic meaning of the text.
With a sync function:
def my_embed_fn(texts):
# Return 2D embeddings for each text
return [[0.1, 0.2] for _ in texts]
embeddings = EmbeddingsLambda(my_embed_fn)
result = embeddings.embed_query("hello") # Returns [0.1, 0.2]
await embeddings.aembed_query("hello") # Also returns [0.1, 0.2]
With an async function:
async def my_async_fn(texts):
return [[0.1, 0.2] for _ in texts]
embeddings = EmbeddingsLambda(my_async_fn)
await embeddings.aembed_query("hello") # Returns [0.1, 0.2]
# Note: embed_query() would raise an error