Files
langchain/docs/extras/integrations/text_embedding/localai.ipynb
T
2023-07-29 08:44:32 -07:00

3.7 KiB

LocalAI

Let's load the LocalAI Embedding class. In order to use the LocalAI Embedding class, you need to have the LocalAI service hosted somewhere and configure the embedding models. See the documentation at https://localai.io/basics/getting_started/index.html and https://localai.io/features/embeddings/index.html.

In [1]:
from langchain.embeddings import LocalAIEmbeddings
In [2]:
embeddings = LocalAIEmbeddings(openai_api_base="http://localhost:8080", model="embedding-model-name")
In [3]:
text = "This is a test document."
In [4]:
query_result = embeddings.embed_query(text)
In [5]:
doc_result = embeddings.embed_documents([text])

Let's load the LocalAI Embedding class with first generation models (e.g. text-search-ada-doc-001/text-search-ada-query-001). Note: These are not recommended models - see here

In [ ]:
from langchain.embeddings import LocalAIEmbeddings
In [ ]:
embeddings = LocalAIEmbeddings(openai_api_base="http://localhost:8080", model="embedding-model-name")
In [ ]:
text = "This is a test document."
In [ ]:
query_result = embeddings.embed_query(text)
In [ ]:
doc_result = embeddings.embed_documents([text])
In [ ]:
# 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"