kiln_ai.datamodel.reranker

 1from enum import Enum
 2from typing import TYPE_CHECKING, Literal, Union
 3
 4from pydantic import Field, PositiveInt
 5from typing_extensions import TypedDict
 6
 7from kiln_ai.datamodel.basemodel import FilenameString, KilnParentedModel
 8
 9if TYPE_CHECKING:
10    from kiln_ai.datamodel.project import Project
11
12
13class RerankerType(str, Enum):
14    """The type of reranking model."""
15
16    COHERE_COMPATIBLE = "cohere_compatible"
17
18
19class CohereCompatibleProperties(TypedDict, total=True):
20    type: Literal[RerankerType.COHERE_COMPATIBLE]
21
22
23class RerankerConfig(KilnParentedModel):
24    """Configuration for reranking search results using a reranking model."""
25
26    name: FilenameString = Field(
27        description="A name for your own reference to identify the reranker config.",
28    )
29    description: str | None = Field(
30        description="A description for your own reference.",
31        default=None,
32    )
33    top_n: PositiveInt = Field(
34        description="The number of results to return from the reranker.",
35    )
36    model_provider_name: str = Field(
37        description="The name of the model provider to use.",
38    )
39    model_name: str = Field(
40        description="The name of the model to use.",
41    )
42    properties: CohereCompatibleProperties = Field(
43        description="The properties of the reranker config, specific to the selected type.",
44        discriminator="type",
45    )
46
47    # Workaround to return typed parent without importing Project
48    def parent_project(self) -> Union["Project", None]:
49        if self.parent is None or self.parent.__class__.__name__ != "Project":
50            return None
51        return self.parent  # type: ignore
class RerankerType(builtins.str, enum.Enum):
14class RerankerType(str, Enum):
15    """The type of reranking model."""
16
17    COHERE_COMPATIBLE = "cohere_compatible"

The type of reranking model.

COHERE_COMPATIBLE = <RerankerType.COHERE_COMPATIBLE: 'cohere_compatible'>
class CohereCompatibleProperties(typing_extensions.TypedDict):
20class CohereCompatibleProperties(TypedDict, total=True):
21    type: Literal[RerankerType.COHERE_COMPATIBLE]
type: Literal[<RerankerType.COHERE_COMPATIBLE: 'cohere_compatible'>]
class RerankerConfig(kiln_ai.datamodel.basemodel.KilnParentedModel):
24class RerankerConfig(KilnParentedModel):
25    """Configuration for reranking search results using a reranking model."""
26
27    name: FilenameString = Field(
28        description="A name for your own reference to identify the reranker config.",
29    )
30    description: str | None = Field(
31        description="A description for your own reference.",
32        default=None,
33    )
34    top_n: PositiveInt = Field(
35        description="The number of results to return from the reranker.",
36    )
37    model_provider_name: str = Field(
38        description="The name of the model provider to use.",
39    )
40    model_name: str = Field(
41        description="The name of the model to use.",
42    )
43    properties: CohereCompatibleProperties = Field(
44        description="The properties of the reranker config, specific to the selected type.",
45        discriminator="type",
46    )
47
48    # Workaround to return typed parent without importing Project
49    def parent_project(self) -> Union["Project", None]:
50        if self.parent is None or self.parent.__class__.__name__ != "Project":
51            return None
52        return self.parent  # type: ignore

Configuration for reranking search results using a reranking model.

name: Annotated[str, BeforeValidator(func=<function name_validator.<locals>.fn at 0x7f90236f9b20>, json_schema_input_type=PydanticUndefined), StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=120, pattern=None)]
description: str | None
top_n: Annotated[int, Gt(gt=0)]
model_provider_name: str
model_name: str
def parent_project(self) -> Optional[kiln_ai.datamodel.Project]:
49    def parent_project(self) -> Union["Project", None]:
50        if self.parent is None or self.parent.__class__.__name__ != "Project":
51            return None
52        return self.parent  # type: ignore
def relationship_name() -> str:
761        def relationship_name_method() -> str:
762            return relationship_name

The type of the None singleton.

def parent_type() -> Type[kiln_ai.datamodel.basemodel.KilnParentModel]:
754        def parent_class_method() -> Type[KilnParentModel]:
755            return cls

The type of the None singleton.

model_config = {'validate_assignment': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

def model_post_init(self: pydantic.main.BaseModel, context: Any, /) -> None:
337def init_private_attributes(self: BaseModel, context: Any, /) -> None:
338    """This function is meant to behave like a BaseModel method to initialise private attributes.
339
340    It takes context as an argument since that's what pydantic-core passes when calling it.
341
342    Args:
343        self: The BaseModel instance.
344        context: The context.
345    """
346    if getattr(self, '__pydantic_private__', None) is None:
347        pydantic_private = {}
348        for name, private_attr in self.__private_attributes__.items():
349            default = private_attr.get_default()
350            if default is not PydanticUndefined:
351                pydantic_private[name] = default
352        object_setattr(self, '__pydantic_private__', pydantic_private)

This function is meant to behave like a BaseModel method to initialise private attributes.

It takes context as an argument since that's what pydantic-core passes when calling it.

Args: self: The BaseModel instance. context: The context.