Skip to content

Serve Embedding Model #383

Closed Answered by eyurtsev
RamishSiddiqui asked this question in Q&A
Discussion options

You must be logged in to vote

Any runnable object can be exposed. Embeddings are not runnables, so you need to re-wrap them into a runnable.

Here's the embeddings interface (not a runnable):

https://github.com/langchain-ai/langchain/blob/bf0b3cc0b5ade1fb95a5b1b6fa260e99064c2e22/libs/core/langchain_core/embeddings.py#L7-L7

The simplest way to do is is using a RunnableLambda.

from langchain_core.runnables import RunnableLambda
embedder = HuggingFaceEmbeddings(...)
runnable_embedder = RunnableLambda(afunc=embedder.aembed_documents)
add_routes(app, runnable_embedder)

That will expose an API around it.

LangServe doesn't do anything to optimize or manage hardware by anything that does local computations. So you should verif…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@shubhankar1477
Comment options

Answer selected by RamishSiddiqui
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants