让我们加载 LocalAI Embedding 类。为了使用 LocalAI Embedding 类,您需要将 LocalAI 服务托管在某处并配置嵌入模型。请参阅文档 localai.io/basics/getting_started/index.html 和 localai.io/features/embeddings/index.html.
pip install -U langchain-localai
from langchain_localai import LocalAIEmbeddings
embeddings = LocalAIEmbeddings(
openai_api_base="http://localhost:8080", model="embedding-model-name"
)
text = "This is a test document."
query_result = embeddings.embed_query(text)
doc_result = embeddings.embed_documents([text])
旧版 langchain-community LocalAIEmbeddings 文档
让我们使用嵌入模型加载 LocalAI Embedding 类。
pip install -U langchain-community
from langchain_community.embeddings import LocalAIEmbeddings
# if you are behind an explicit proxy, you can use the OPENAI_PROXY environment variable to pass through
os.environ["OPENAI_PROXY"] = "http://proxy.yourcompany.com:8080"
embeddings = LocalAIEmbeddings(
openai_api_base="http://localhost:8080", model="embedding-model-name"
)
text = "This is a test document."
query_result = embeddings.embed_query(text)
doc_result = embeddings.embed_documents([text])