Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
OurBuilding Ambient Agents with LangGraph course is now available on LangChain Academy!
Open In ColabOpen on GitHub

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 thelangchain-lindorm-integration integration package.

%pip install-qU"langchain-lindorm-integration"

Credentials

Head tohere to sign up to Lindorm and generate the ak/sk.

import os


classConfig:
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.embeddingsimport LindormAIEmbeddings
from langchain_lindorm_integration.vectorstoresimport 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.documentsimport 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': []}

Query vector store

Once your vector store has been created and the relevant documents have been added you will most likely wish to query it during the running of your chain or agent.

Query directly

Performing a simple similarity search can be done as follows:

results= vector_store.similarity_search(query="thud", k=1)
for docin results:
print(f"*{doc.page_content} [{doc.metadata}]")
* foo [{'source': 'https://example.com'}]

If you want to execute a similarity search and receive the corresponding scores you can run:

results= vector_store.similarity_search_with_score(query="thud", k=1)
for doc, scorein results:
print(f"* [SIM={score:3f}]{doc.page_content} [{doc.metadata}]")
* [SIM=0.671268] foo [{'source': 'https://example.com'}]

Usage for retrieval-augmented generation

For guides on how to use this vector store for retrieval-augmented generation (RAG), see the following sections:

API reference

For detailed documentation of all LindormVectorStore features and configurations head tothe API reference.

Related


[8]ページ先頭

©2009-2025 Movatter.jp