LindormVectorStore
This notebook covers how to get started with the Lindorm vector store.
Setup
To access Lindorm vector stores you'll need to create a Lindorm account, get the ak/sk, and install the langchain-lindorm-integration
integration package.
%pip install -qU "langchain-lindorm-integration"
Credentials
Head to here to sign up to Lindorm and generate the ak/sk.
import os
class Config:
SEARCH_ENDPOINT = os.environ.get("SEARCH_ENDPOINT", "SEARCH_ENDPOINT")
SEARCH_USERNAME = os.environ.get("SEARCH_USERNAME", "root")
SEARCH_PWD = os.environ.get("SEARCH_PASSWORD", "<PASSWORD>")
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 model
Initialization
here we use the embedding model deployed on Lindorm AI Service.
from langchain_lindorm_integration.embeddings import LindormAIEmbeddings
from langchain_lindorm_integration.vectorstores import LindormVectorStore
embeddings = LindormAIEmbeddings(
endpoint=Config.AI_LLM_ENDPOINT,
username=Config.AI_USERNAME,
password=Config.AI_PWD,
model_name=Config.AI_DEFAULT_EMBEDDING_MODEL,
)
index = "test_index"
vector = embeddings.embed_query("hello word")
dimension = len(vector)
vector_store = LindormVectorStore(
lindorm_search_url=Config.SEARCH_ENDPOINT,
embedding=embeddings,
http_auth=(Config.SEARCH_USERNAME, Config.SEARCH_PWD),
dimension=dimension,
embeddings=embeddings,
index_name=index,
)
Manage vector store
Add items to vector store
from langchain_core.documents import Document
document_1 = Document(page_content="foo", metadata={"source": "https://example.com"})
document_2 = Document(page_content="bar", metadata={"source": "https://example.com"})
document_3 = Document(page_content="baz", metadata={"source": "https://example.com"})
documents = [document_1, document_2, document_3]
vector_store.add_documents(documents=documents, ids=["1", "2", "3"])
API Reference:Document
['1', '2', '3']
Delete items from vector store
vector_store.delete(ids=["3"])
{'took': 400,
'timed_out': False,
'total': 1,
'deleted': 1,
'batches': 1,
'version_conflicts': 0,
'noops': 0,
'retries': {'bulk': 0, 'search': 0},
'throttled_millis': 0,
'requests_per_second': -1.0,
'throttled_until_millis': 0,
'failures': []}