Skip to main content

LocalAI

让我们加载 LocalAI Embedding 类。要使用 LocalAI Embedding 类,您需要在某处托管 LocalAI 服务并配置嵌入模型。请参阅文档 https://localai.io/basics/getting_started/index.htmlhttps://localai.io/features/embeddings/index.html。

from langchain_community.embeddings 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])

让我们使用第一代模型(例如 text-search-ada-doc-001/text-search-ada-query-001)加载 LocalAI Embedding 类。注意:这些模型不推荐使用 - 请参见 这里

from langchain_community.embeddings 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])
import os

# 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"

相关


此页面是否有帮助?


您还可以留下详细的反馈 在 GitHub 上