diff --git a/src/oss/python/integrations/document_transformers/localai_rerank.mdx b/src/oss/python/integrations/document_transformers/localai_rerank.mdx new file mode 100644 index 000000000..e569b8290 --- /dev/null +++ b/src/oss/python/integrations/document_transformers/localai_rerank.mdx @@ -0,0 +1,39 @@ +--- +title: LocalAI Reranker +--- + + +**`langchain-localai` is a 3rd party integration package for LocalAI. It provides a simple way to use LocalAI services in LangChain.** + +The source code is available on [GitHub](https://github.com/mkhludnev/langchain-localai) + + + +This notebook shows how to use [LocalAI Reranker API](https://localai.io/features/reranker/) for document compression and retrieval. +Let's load the `LocalAIRerank` class. In order to use the `LocalAIRerank` class, you need to have the LocalAI service hosted somewhere and configure the reranker. See the documentation at [localai.io/basics/getting_started/index.html](https://localai.io/basics/getting_started/index.html) and [localai.io/features/reranker/index.html](https://localai.io/features/reranker/index.html). + +```python +pip install -U langchain-localai +``` + +```python +import os +from langchain_localai import LocalAIRerank +from langchain_core.documents import Document + +# Set your LocalAI/OpenAI API key as an environment variable for security. +# For example, in your shell: export OPENAI_API_KEY="your-key-here" +reranker = LocalAIRerank( + openai_api_key=os.environ.get("OPENAI_API_KEY"), + model="bge-reranker-v2-m3", + openai_api_base="http://localhost:8080", +) +reranked_docs = reranker.compress_documents( + documents=[ + Document(page_content="Green tea is rich in antioxidants and may improve brain function."), + Document(page_content="Coffee contains caffeine and can increase alertness."), + Document(page_content="Black tea has a strong flavor and contains various polyphenols."), + ], + query="What are the health benefits of green tea?" +) +``` diff --git a/src/oss/python/integrations/text_embedding/localai.mdx b/src/oss/python/integrations/text_embedding/localai.mdx index 0106d2f7c..9f25e9ab1 100644 --- a/src/oss/python/integrations/text_embedding/localai.mdx +++ b/src/oss/python/integrations/text_embedding/localai.mdx @@ -1,5 +1,5 @@ --- -title: LocalAI +title: LocalAI Embeddings ---