LangChain interfaces – embeddings and vector stores
Beyond interfaces for documents and retrievers, as discussed in Chapter 3, LangChain offers interfaces for embedding models and vector stores. These interfaces simplify the process of constructing a vector search architecture.
Embeddings
The Embedding
class provides a standardized Runnable
for embedding models.
The key methods of this class are embed_query
and embed_documents
. The main difference is that embed_query
accepts a single text input, while embed_documents
accepts multiple texts:
from langchain_google_vertexai import VertexAIEmbeddings model_name = "my-embedding-model-name" # textembeding-gecko@003 embedding_model = VertexAIEmbeddings(model_name=model_name) single_embedding = embedding_model.embed_query("User query") multiple_embeddings = embedding_model.embed_documents([ "Sample text 1", "Sample text 2", ...