Closed idefa closed 2 months ago
Hello @idefa! I'm here to help you with any bugs, questions, or contributions you may have. I'll do my best to assist you while we wait for a human maintainer.
To set up a knowledge base with the Rerank model for mixed search using LocalAI, you can follow these steps:
Create a Knowledge Base Application:
Choose a Recall Mode:
Configure the Rerank Model:
Set the Rerank Model:
Here is an example of how you can set up and use the LocalaiRerankModel
:
import os
from core.model_runtime.entities.rerank_entities import RerankResult, RerankDocument
from core.model_runtime.model_providers.localai.rerank.rerank import LocalaiRerankModel
# Initialize the LocalaiRerankModel
rerank_model = LocalaiRerankModel()
# Define model credentials
credentials = {
'server_url': os.environ.get('LOCALAI_SERVER_URL'),
'api_key': 'your-api-key'
}
# Define the model name
model_name = 'bge-reranker-base'
# Define the search query and documents
query = "What is the capital of the United States?"
docs = [
"Carson City is the capital city of the American state of Nevada. At the 2010 United States Census, Carson City had a population of 55,274.",
"The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean that are a political division controlled by the United States. Its capital is Saipan."
]
# Invoke the rerank model
try:
rerank_result: RerankResult = rerank_model._invoke(
model=model_name,
credentials=credentials,
query=query,
docs=docs,
score_threshold=0.8,
top_n=5,
user="abc-123"
)
# Process the rerank result
for doc in rerank_result.docs:
print(f"Document: {doc.text}, Score: {doc.score}")
except Exception as e:
print(f"Error invoking rerank model: {e}")
This code sets up the LocalaiRerankModel
, validates the credentials, and invokes the rerank model with a search query and documents. The results are then processed and printed [1][2][3][4].
To continue talking to Dosu, mention @dosu.
Self Checks
Provide a description of requested docs changes
Knowledge base setup, mixed search requires enabling the Rerank model, but only LocalAI supports the Rerank model locally. Is there a complete example?