Filter Extractor
Modules concerning the filter extractor used in Gen AI applications.
FieldDescriptor
Bases: BaseModel
Describes a single filterable field in the target datastore index.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Dot-notation path to the field. |
python_type |
Any
|
Any type expressible as a JSON Schema (validated at construction). |
description |
str | None
|
Human-readable description of the field for LLM context. |
allowed_values |
list[Any] | None
|
Enumerated allowed values for enum-like fields. |
allowed_operators |
list[FilterOperator]
|
List of filter operators permitted on this field. |
example_values |
list[Any] | None
|
Example values to help LLM understand field semantics. |
FieldKey
Keys for field metadata.
FilterExtractionResult
Bases: BaseModel
Typed output of BaseFilterExtractor.extract().
Attributes:
| Name | Type | Description |
|---|---|---|
query |
str
|
The extracted query string. |
query_filter |
QueryFilter | None
|
The extracted query filter. |
query_options |
QueryOptions
|
The extracted query options. |
retriever_params |
RetrieverParams | None
|
The extracted retriever parameters. |
MetadataCatalog
Bases: BaseModel
Schema of filterable fields for a target datastore index.
Attributes:
| Name | Type | Description |
|---|---|---|
fields |
list[FieldDescriptor]
|
List of field descriptors defining the available filterable fields. |
from_pydantic(model, prefix)
classmethod
Build a MetadataCatalog by reflecting on a Pydantic document model.
Extracts field metadata by introspecting the Pydantic model's fields. For each field, it resolves the type annotation, maps it to a datastore-compatible type string, and extracts optional field attributes (description, allowed_values, allowed_operators, example_values) from Pydantic field attributes.
Examples:
class Meta(BaseModel):
status: Literal["active", "archived"]
score: float
class Doc(BaseModel):
meta: Meta
catalog = MetadataCatalog.from_pydantic(Doc, prefix="meta")
Args: model (type[BaseModel]): The Pydantic document model class. prefix (str): Dot-notation path to the sub-model to reflect.
Returns:
| Name | Type | Description |
|---|---|---|
MetadataCatalog |
MetadataCatalog
|
Metadata catalog with one FieldDescriptor per reflected field. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |