from __future__ import annotations
from ._data import schema_sha256, schema_version
from .discriminator import autofix, find_unknown_funcs, suggest_func
from .knowledge import (
find_tutorial,
list_models,
model_parameters,
search_tutorials,
semantic_search_with_fallback,
)
from .models import (
ConfigFix,
Diagnostic,
Explanation,
FixResult,
ModelCatalog,
ModelInfo,
ModelParameters,
ParameterInfo,
SemanticMatch,
Tutorial,
TutorialSearchResult,
ValidationResult,
)
from .validation import deep_check, explain_config, validate_config
__version__ = "0.6.1"
[docs]
def semantic_search(query: str, limit: int = 5) -> list[SemanticMatch]:
"""Rank tutorial passages by meaning, with the local vector index.
Needs the ``rag`` extra and an index built by `build_index` or
``pyxel-config index``, and raises an error when either is missing. To
fall back to keyword matching instead, use
`semantic_search_with_fallback`.
Parameters
----------
query : str
What to look for, in plain words.
limit : int, default 5
The most passages to return.
Returns
-------
list of SemanticMatch
The closest passages first.
"""
from .rag import semantic_search as _semantic_search
return _semantic_search(query, limit=limit)
[docs]
def build_index(force: bool = True) -> int:
"""Build the local vector index of tutorial passages.
Needs the ``rag`` extra, and downloads the embedding model on first use.
The index is written to ``~/.cache/pyxel-config-core/qdrant``, or to the
folder the ``PYXEL_CONFIG_CORE_INDEX`` environment variable names.
Parameters
----------
force : bool, default True
Delete any existing index and build it afresh. When False, an
existing index is updated in place.
Returns
-------
int
How many passages were indexed.
"""
from .rag import build_index as _build_index
return _build_index(force=force)
__all__ = [
"validate_config",
"explain_config",
"deep_check",
"autofix",
"find_tutorial",
"search_tutorials",
"semantic_search",
"semantic_search_with_fallback",
"build_index",
"list_models",
"model_parameters",
"find_unknown_funcs",
"suggest_func",
"schema_version",
"schema_sha256",
"Diagnostic",
"ValidationResult",
"Explanation",
"Tutorial",
"TutorialSearchResult",
"SemanticMatch",
"ModelParameters",
"ModelInfo",
"ModelCatalog",
"ParameterInfo",
"ConfigFix",
"FixResult",
]