LindormAIEmbeddings
This will help you get started with Lindorm embedding models using LangChain.
Overview
Integration details
Provider | Package |
---|---|
Lindorm | langchain-lindorm-integration |
Setup
To access Lindorm embedding models you'll need to create a Lindorm account, get AK&SK, and install thelangchain-lindorm-integration
integration package.
Credentials
You can get you credentials in theconsole
import os
classConfig:
AI_LLM_ENDPOINT= os.environ.get("AI_ENDPOINT","<AI_ENDPOINT>")
AI_USERNAME= os.environ.get("AI_USERNAME","root")
AI_PWD= os.environ.get("AI_PASSWORD","<PASSWORD>")
AI_DEFAULT_EMBEDDING_MODEL="bge_m3_model"# set to your deployed model
Installation
The LangChain Lindorm integration lives in thelangchain-lindorm-integration
package:
%pip install-qU langchain-lindorm-integration
Note: you may need to restart the kernel to use updated packages.
Instantiation
Now we can instantiate our model object and generate chat completions:
from langchain_lindorm_integrationimport LindormAIEmbeddings
embeddings= LindormAIEmbeddings(
endpoint=Config.AI_LLM_ENDPOINT,
username=Config.AI_USERNAME,
password=Config.AI_PWD,
model_name=Config.AI_DEFAULT_EMBEDDING_MODEL,
)
Indexing and Retrieval
Embedding models are often used in retrieval-augmented generation (RAG) flows, both as part of indexing data as well as later retrieving it. For more detailed instructions, please see ourRAG tutorials.
Below, see how to index and retrieve data using theembeddings
object we initialized above. In this example, we will index and retrieve a sample document in theInMemoryVectorStore
.
# Create a vector store with a sample text
from langchain_core.vectorstoresimport InMemoryVectorStore
text="LangChain is the framework for building context-aware reasoning applications"
vectorstore= InMemoryVectorStore.from_texts(
[text],
embedding=embeddings,
)
# Use the vectorstore as a retriever
retriever= vectorstore.as_retriever()
# Retrieve the most similar text
retrieved_documents= retriever.invoke("What is LangChain?")
# show the retrieved document's content
retrieved_documents[0].page_content
'LangChain is the framework for building context-aware reasoning applications'
Direct Usage
Under the hood, the vectorstore and retriever implementations are callingembeddings.embed_documents(...)
andembeddings.embed_query(...)
to create embeddings for the text(s) used infrom_texts
and retrievalinvoke
operations, respectively.
You can directly call these methods to get embeddings for your own use cases.
Embed single texts
You can embed single texts or documents withembed_query
:
single_vector= embeddings.embed_query(text)
print(str(single_vector)[:100])# Show the first 100 characters of the vector
[-0.016254117712378502, -0.01154549140483141, 0.0042558759450912476, -0.011416379362344742, -0.01770
Embed multiple texts
You can embed multiple texts withembed_documents
:
text2=(
"LangGraph is a library for building stateful, multi-actor applications with LLMs"
)
two_vectors= embeddings.embed_documents([text, text2])
for vectorin two_vectors:
print(str(vector)[:100])# Show the first 100 characters of the vector
[-0.016254086047410965, -0.011545476503670216, 0.0042558712884783745, -0.011416426859796047, -0.0177
[-0.07268096506595612, -3.236892371205613e-05, -0.0019329536007717252, -0.030644644051790237, -0.018
API Reference
For detailed documentation onLindormEmbeddings
features and configuration options, please refer to theAPI reference.
Related
- Embedding modelconceptual guide
- Embedding modelhow-to guides