Skip to content

feat: add kanon-2-reranker integration#1

Open
yasinkip wants to merge 4 commits into
isaacus-dev:mainfrom
yasinkip:main
Open

feat: add kanon-2-reranker integration#1
yasinkip wants to merge 4 commits into
isaacus-dev:mainfrom
yasinkip:main

Conversation

@yasinkip

Copy link
Copy Markdown

Kanon 2 Reranker Integration

Features:

  • Added IsaacusRerank Class

Documentation:

  • Added reranking notebook under docs/
  • Updated README to include reranker example

Fixes:

  • Fixed bug in embedding integration

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for Isaacus “kanon-2-reranker” as a LangChain BaseDocumentCompressor, alongside docs and tests, and adjusts embeddings client construction to handle SecretStr API keys correctly.

Changes:

  • Introduces IsaacusRerank (sync + async) document reranking compressor.
  • Adds unit + integration tests for reranking behavior and initialization.
  • Updates docs/README examples and fixes embeddings API key handling when passed as SecretStr.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
langchain_isaacus/rerank.py New reranker integration implementing compress_documents / acompress_documents.
langchain_isaacus/embeddings.py Adjusts client creation to unwrap SecretStr API keys.
langchain_isaacus/__init__.py Exports IsaacusRerank from the package root.
tests/unit_tests/test_rerank.py Adds unit tests for reranker initialization.
tests/integration_tests/test_rerank.py Adds integration tests that call the live reranking API.
docs/text_embedding.ipynb Updates embeddings notebook links/text formatting.
docs/reranking.ipynb Adds reranking notebook with an end-to-end example.
README.md Adds reranking usage snippet and updates embeddings snippet.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread langchain_isaacus/embeddings.py Outdated
Comment thread tests/integration_tests/test_rerank.py
Comment on lines +23 to +25
documents = [Document("foo bar"), Document("bar foo"), Document("foo")]
rerank= IsaacusRerank(model=MODEL)
output = rerank.compress_documents(documents, query)
@@ -0,0 +1,28 @@
"""Test embedding model integration."""
Comment on lines +11 to +13
def test_initialization_kanon_2_reranker() -> None:
"""Test embedding model initialization."""
rr = IsaacusRerank(api_key=SecretStr("NOT_A_VALID_KEY"), model=MODEL)
Comment thread docs/reranking.ipynb
"source": [
"## Instantiation\n",
"\n",
"Now we can instantiate our model object and generate chat completions:"
Comment on lines 13 to 22
__all__ = [
"ChatIsaacus",
"IsaacusVectorStore",
"IsaacusEmbeddings",
"IsaacusLoader",
"IsaacusRetriever",
"IsaacusRerank",
"IsaacusToolkit",
"IsaacusTool",
"__version__",
Comment thread README.md
from langchain_core.documents import Document

rerankings = IsaacusRerank(model="kanon-2-reranker")
embeddings.compress_documents(
Comment thread docs/reranking.ipynb
"# Show the ranked results\n",
"print(query)\n",
"for idx, doc in enumerate(reranked):\n",
" print(f\"Rank {idx+1} ({doc.metadata[\"score\"]:.4f}): {doc.page_content}\")"
Comment on lines +60 to +66
def rerank(
self, documents: Sequence[Union[Document, str]], query: str
) -> list[dict[str, Any]]:
"""Returns an ordered list of documents ordered by their relevance to
the query.
"""
docs = [self._document_to_str(doc) for doc in documents]
@umarbutler umarbutler self-requested a review April 16, 2026 07:01
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@umarbutler

Copy link
Copy Markdown
Collaborator

@copilot apply changes based on the comments in this thread

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an Isaacus “kanon-2-reranker” integration to the langchain_isaacus package, alongside docs/examples and a small fix to the embeddings client initialization.

Changes:

  • Introduces IsaacusRerank (BaseDocumentCompressor) with sync/async reranking and top_n support.
  • Fixes embeddings client construction to unwrap SecretStr API keys before passing them to the Isaacus client.
  • Adds unit/integration tests and documentation (new reranking notebook + README updates).

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
langchain_isaacus/rerank.py New reranker implementation (sync/async) that compresses documents by Isaacus relevance score.
langchain_isaacus/embeddings.py Changes how API keys are passed to Isaacus clients (unwrap SecretStr).
langchain_isaacus/__init__.py Exports IsaacusRerank at package level.
tests/unit_tests/test_rerank.py Adds unit tests covering reranker initialization behavior.
tests/integration_tests/test_rerank.py Adds integration tests for reranking behavior (sync/async, top_n).
docs/text_embedding.ipynb Updates embedding notebook links/text and minor formatting.
docs/reranking.ipynb Adds a new reranking “getting started” notebook.
README.md Adds a reranking usage example and adjusts embeddings example.
Comments suppressed due to low confidence (1)

langchain_isaacus/init.py:23

  • __all__ lists several symbols (ChatIsaacus, IsaacusVectorStore, IsaacusLoader, etc.) that aren’t imported or defined anywhere in this package (the only modules present are embeddings.py and rerank.py). As a result, from langchain_isaacus import ChatIsaacus will raise AttributeError. Either import/re-export these symbols here (possibly via lazy imports) or remove them from __all__ to match what the package actually exposes.
__all__ = [
    "ChatIsaacus",
    "IsaacusVectorStore",
    "IsaacusEmbeddings",
    "IsaacusLoader",
    "IsaacusRetriever",
    "IsaacusRerank",
    "IsaacusToolkit",
    "IsaacusTool",
    "__version__",
]

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread README.md
Comment on lines +34 to +36
rerankings = IsaacusRerank(model="kanon-2-reranker")
embeddings.compress_documents(
documents=[Document("The meaning of life is ...")],
Comment thread docs/reranking.ipynb
"# Show the ranked results\n",
"print(query)\n",
"for idx, doc in enumerate(reranked):\n",
" print(f\"Rank {idx+1} ({doc.metadata[\"score\"]:.4f}): {doc.page_content}\")"
Comment thread langchain_isaacus/embeddings.py Outdated
Comment on lines 117 to 129
def _get_api_key(self) -> str:
if isinstance(self.api_key, SecretStr):
api_key = self.api_key.get_secret_value()
else:
api_key = self.api_key

return api_key

def _get_client(self) -> Isaacus:
if not self._client:
self._client = Isaacus(
api_key=self.api_key,
api_key=self._get_api_key(),
base_url=self.base_url,
Comment on lines +13 to +16
query = "foo"
documents = [Document("foo bar")]
rerank = IsaacusRerank(model=MODEL)
output = rerank.compress_documents(documents, query)
Comment on lines +31 to +34
query = "foo"
documents = [Document("foo bar"), Document("bar foo"), Document("foo")]
rerank = IsaacusRerank(model=MODEL)
output = await rerank.acompress_documents(documents, query)
Comment on lines +1 to +14
"""Test embedding model integration."""

from langchain_core.documents import BaseDocumentCompressor
from pydantic import SecretStr

from langchain_isaacus import IsaacusRerank

MODEL = "kanon-2-reranker"


def test_initialization_kanon_2_reranker() -> None:
"""Test embedding model initialization."""
rr = IsaacusRerank(api_key=SecretStr("NOT_A_VALID_KEY"), model=MODEL)
assert isinstance(rr, BaseDocumentCompressor)
Comment thread docs/reranking.ipynb
"source": [
"## Instantiation\n",
"\n",
"Now we can instantiate our model object and generate chat completions:"
Comment on lines +22 to +25
query = "foo"
documents = [Document("foo bar"), Document("bar foo"), Document("foo")]
rerank = IsaacusRerank(model=MODEL)
output = rerank.compress_documents(documents, query)
Comment on lines +40 to +43
query = "foo"
documents = [Document("foo bar"), Document("bar foo"), Document("foo")]
rerank = IsaacusRerank(model=MODEL, top_n=2)
output = rerank.compress_documents(documents, query)
@umarbutler

Copy link
Copy Markdown
Collaborator

@copilot apply changes based on the comments in this thread

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants