This will help you get started with Lindorm embedding models using LangChain.
Overview Integration details SetupTo access Lindorm embedding models you'll need to create a Lindorm account, get AK&SK, and install the langchain-lindorm-integration
integration package.
You can get you credentials in the console
import os
class Config:
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"
Installation
The LangChain Lindorm integration lives in the langchain-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_integration import 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 our RAG tutorials.
Below, see how to index and retrieve data using the embeddings
object we initialized above. In this example, we will index and retrieve a sample document in the InMemoryVectorStore
.
from langchain_core.vectorstores import InMemoryVectorStore
text = "LangChain is the framework for building context-aware reasoning applications"
vectorstore = InMemoryVectorStore.from_texts(
[text],
embedding=embeddings,
)
retriever = vectorstore.as_retriever()
retrieved_documents = retriever.invoke("What is LangChain?")
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 calling embeddings.embed_documents(...)
and embeddings.embed_query(...)
to create embeddings for the text(s) used in from_texts
and retrieval invoke
operations, respectively.
You can directly call these methods to get embeddings for your own use cases.
Embed single textsYou can embed single texts or documents with embed_query
:
single_vector = embeddings.embed_query(text)
print(str(single_vector)[:100])
[-0.016254117712378502, -0.01154549140483141, 0.0042558759450912476, -0.011416379362344742, -0.01770
Embed multiple texts
You can embed multiple texts with embed_documents
:
text2 = (
"LangGraph is a library for building stateful, multi-actor applications with LLMs"
)
two_vectors = embeddings.embed_documents([text, text2])
for vector in two_vectors:
print(str(vector)[:100])
[-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 on LindormEmbeddings
features and configuration options, please refer to the API reference.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4