Abstract base classes for extending contextual-distillation.
BaseChunker
Abstract class for implementing custom document chunkers.
from contextual_distillation import BaseChunker, Chunk
class MyChunker(BaseChunker):
async def chunk(self, document: str) -> list[Chunk]:
return [
Chunk(text=paragraph, metadata={"index": i})
for i, paragraph in enumerate(document.split("\n\n"))
]
BaseDownloader
Abstract class for implementing custom document retrieval.
from contextual_distillation import BaseDownloader, Document
class MyDownloader(BaseDownloader):
async def download(self, url: str) -> Document:
response = await fetch(url)
return Document(
content=response.text,
metadata={"source": url},
)
BaseDistiller
Abstract class for implementing custom distillers with specialized extraction logic.
from contextual_distillation import BaseDistiller, DistillResult
class MyDistiller(BaseDistiller):
async def distill(self, query: str, chunk: str) -> DistillResult:
return DistillResult(
content=extracted_text,
confidence=0.95,
)