Cohere Rerank
Cohere Rerank is a tool that takes a list of documents returned from a search and uses Cohere’s AI to reorder them so that the most relevant ones appear first. It’s useful when you want to improve the quality of search results before showing them to users or feeding them into another part of your workflow.
How it Works
When you feed the component a set of documents (the Search Results), a query string (the Search Query), and a chosen Cohere model, it calls the Cohere Rerank API. The API scores each document based on how well it matches the query and returns the top N documents in order of relevance. The component then outputs these reordered documents as Reranked Documents.
Inputs
Credential
This component needs a Cohere API credential. First add a Cohere API credential in Nappai’s Credentials section, then select it in the component’s Credential field.
Input Fields
- Search Results: The list of documents that came from a previous search or vector store.
- Model: Choose which Cohere reranking model to use. Options include English and multilingual versions.
- Search Query: The text query that the documents should be ranked against.
- Top N: How many of the top‑ranked documents you want to keep.
Outputs
- Reranked Documents: The same documents you fed in, but reordered so that the most relevant ones are first. This output can be passed to other components, displayed to users, or stored for later use.
Usage Example
- Search – Use a vector store search component to find documents that match a user’s query.
- Rerank – Connect the search output to the Search Results input of Cohere Rerank.
- Configure – Pick a model (e.g., rerank-english-v3.0), set the Search Query to the user’s question, and choose Top N (e.g., 5).
- Output – The component returns the top 5 documents, now sorted by relevance, which you can display or feed into another step.
Related Components
- Vector Store Search – Retrieves documents from a vector database.
- Document Compressor – Reduces document size or removes duplicates.
- Cohere Embedding – Generates embeddings for text using Cohere.
- LangChain Retrieval – Combines search and retrieval logic in a single workflow.
Tips and Best Practices
- Model Choice: Use the English model if your queries are in English; otherwise, pick a multilingual model.
- Top N: Start with a small number (e.g., 3–5) to keep the output concise, then adjust if needed.
- Testing: Run the component on a sample set of documents to verify that the ranking matches your expectations before deploying.
- Credential Management: Store the Cohere API key in Nappai’s secure credential store and never expose it in the UI or logs.
Security Considerations
- The Cohere API key is sensitive; keep it in the credential store and never hard‑code it in your workflow.
- Ensure that only authorized users have access to the component and the credentials it uses.
- Monitor API usage to detect any unexpected or excessive calls that could indicate misuse.