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    COHERE_COMPATIBLE = "cohere_compatible"
15
16
17class CohereCompatibleProperties(TypedDict, total=True):
18    type: Literal[RerankerType.COHERE_COMPATIBLE]
19
20
21class RerankerConfig(KilnParentedModel):
22    name: FilenameString = Field(
23        description="A name for your own reference to identify the reranker config.",
24    )
25    description: str | None = Field(
26        description="A description for your own reference.",
27        default=None,
28    )
29    top_n: PositiveInt = Field(
30        description="The number of results to return from the reranker.",
31    )
32    model_provider_name: str = Field(
33        description="The name of the model provider to use.",
34    )
35    model_name: str = Field(
36        description="The name of the model to use.",
37    )
38    properties: CohereCompatibleProperties = Field(
39        description="The properties of the reranker config, specific to the selected type.",
40        discriminator="type",
41    )
42
43    # Workaround to return typed parent without importing Project
44    def parent_project(self) -> Union["Project", None]:
45        if self.parent is None or self.parent.__class__.__name__ != "Project":
46            return None
47        return self.parent  # type: ignore
class RerankerType(builtins.str, enum.Enum):
14class RerankerType(str, Enum):
15    COHERE_COMPATIBLE = "cohere_compatible"

str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.

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

Base model for Kiln models that have a parent-child relationship. This base class is for child models.

This class provides functionality for managing hierarchical relationships between models, including parent reference handling and file system organization.

Attributes: parent (KilnBaseModel): Reference to the parent model instance. Not persisted, just in memory.

name: Annotated[str, BeforeValidator(func=<function name_validator.<locals>.fn at 0x7f2f1ec0c9a0>, json_schema_input_type=PydanticUndefined)]
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]:
45    def parent_project(self) -> Union["Project", None]:
46        if self.parent is None or self.parent.__class__.__name__ != "Project":
47            return None
48        return self.parent  # type: ignore
def relationship_name() -> str:
713        def relationship_name_method() -> str:
714            return relationship_name

The type of the None singleton.

def parent_type() -> Type[kiln_ai.datamodel.basemodel.KilnParentModel]:
706        def parent_class_method() -> Type[KilnParentModel]:
707            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.