queries#

Structured, injection-safe search helpers over the kernels table.

Shared by the KernelFoundry MCP server (local execution) and the gui app’s REST API (remote execution), so both modes run the exact same query and return identical results.

Module Attributes

SEARCH_PREVIEW_LEN

Max characters of output_code included in kernel_to_preview_dict before truncating.

MIN_IMPROVE_OVER_NATIVE

kernels below this speedup are not meaningfully better than native and are not useful as examples, so it is always applied rather than exposed as a filter.

Functions

get_kernel(kernel_id)

Fetch a single kernel row by primary key, or None if it doesn't exist.

kernel_to_full_dict(kernel[, ...])

Full get_kernel result entry: every field an agent would plausibly want.

kernel_to_preview_dict(kernel)

Compact search_kernels result entry: metadata plus a truncated code preview.

search_kernels(filters[, limit, offset])

Search the kernels table with a fixed set of safe, parameterized filters.

kernelfoundry.eval_pipeline.database.queries.SEARCH_PREVIEW_LEN = 300#

Max characters of output_code included in kernel_to_preview_dict before truncating.

kernelfoundry.eval_pipeline.database.queries.MIN_IMPROVE_OVER_NATIVE = 0.5#

kernels below this speedup are not meaningfully better than native and are not useful as examples, so it is always applied rather than exposed as a filter.

Type:

Baseline floor

kernelfoundry.eval_pipeline.database.queries.search_kernels(filters: dict, limit: int = 20, offset: int = 0) → tuple[list[Kernel], int][source]#

Search the kernels table with a fixed set of safe, parameterized filters.

Always restricted to status == "correct" and improve_over_native > MIN_IMPROVE_OVER_NATIVE – incorrect or non-improving kernels aren’t useful examples.

Results are diversified across task_name rather than just sorted by speedup: Each task’s single best kernel is returned first (that first batch itself ordered by speedup, best task first), then each task’s second-best, and so on.

Parameters:
  • filters – Optional keys — case-insensitive exact match: output_language, task_name, gpu_arch; substring match: task_name_contains, output_code_contains, gpu_arch_contains; all-term code match: output_code_terms; numeric range: max_runtime, min_speedup/max_speedup (further narrows above the baseline floor; speedup is the ratio stored in Kernel.improve_over_native).

  • limit – Max rows to return, clamped to [1, MAX_LIMIT].

  • offset – Row offset for pagination.

Returns:

Tuple of (matching Kernel rows for this page, total matching row count).

kernelfoundry.eval_pipeline.database.queries.get_kernel(kernel_id: int) → Kernel | None[source]#

Fetch a single kernel row by primary key, or None if it doesn’t exist.

kernelfoundry.eval_pipeline.database.queries.kernel_to_preview_dict(kernel: Kernel) → dict[str, Any][source]#

Compact search_kernels result entry: metadata plus a truncated code preview.

kernelfoundry.eval_pipeline.database.queries.kernel_to_full_dict(kernel: Kernel, include_profiler_data: bool = False) → dict[str, Any][source]#

Full get_kernel result entry: every field an agent would plausibly want.