LocalAI
让我们加载 LocalAI Embedding 类。为了使用 LocalAI Embedding 类,您需要在某个地方托管 LocalAI 服务并配置嵌入模型。请参阅https://localai.io/basics/getting_started/index.html和https://localai.io/features/embeddings/index.html中的文档。
from langchain_community.embeddings import LocalAIEmbeddings
API 参考: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
API 参考: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"