We’re adding a new AI-powered reranking API for the legal domain to the Isaacus API, the world’s first legal AI API.
Using our new reranking endpoint, you can have our benchmark-smashing Kanon Universal Classifier and Kanon Universal Classifier Mini models score and sort documents by their relevance to search queries, helping to ensure that only the most relevant legal search results reach your users.
The introduction of this new endpoint marks a small but important step towards our broader mission of improving every aspect of the next generation of legal databases and legal retrieval augmented generation (RAG) pipelines,
where reranking is becoming an increasingly important ingredient to success.
As with any reranking API, we expect our reranking endpoint to most often be used in conjunction with less computationally expensive but also less accurate information retrieval techniques like BM25 and dense embeddings.
By using those techniques to retrieve a large set of documents that may potentially be relevant to a user’s query, our reranking endpoint can then be used to score and resort those documents with great precision, before the most relevant subset of documents is present to the user (or, when integrated into a RAG pipeline, to a generative model).
To get started building with our reranking API, you can check out its documentation or, assuming you’ve already set up an Isaacus account and API client, consult the code snippet below, which sorts legal texts based on their relevance to a query asking what the essential elements of a negligence claim are.
from isaacus import Isaacus
# Create an Isaacus API client.
client = Isaacus(api_key="PASTE_YOUR_API_KEY_HERE")
# Define a query and a list of texts to rerank.
query = "What are the essential elements required to establish a negligence claim?"
texts = [
"To form a contract, there must be an offer, acceptance, consideration, "
"and mutual intent to be bound.",
"Criminal cases involve a completely different standard, requiring proof "
"beyond a reasonable doubt.",
"In a negligence claim, the plaintiff must prove duty, breach, causation, "
"and damages.",
"Negligence in tort law requires establishing a duty of care that the "
"defendant owed to the plaintiff.",
"The concept of negligence is central to tort law, with courts assessing "
"whether a breach of duty caused harm."
]
# Rerank the texts.
reranking = client.rerankings.create(
model="kanon-universal-classifier",
query=query,
texts=texts,
)
# Unpack the results.
results = [{
"index": result.index,
"text": texts[result.index],
"score": result.score,
} for result in reranking.results]
# Print the reranked results.
for result in results:
print(
'-' * 10,
f'index = {result["index"]} | score = {result["score"]:.2f}',
'-' * 10,
'\n',
result["text"],
end='\n\n',
)