5f4f1f7508
Añade campos params y output al frontmatter YAML de las 506 funciones del registry. Cada parámetro tiene descripción semántica (qué representa, unidades, rango típico) y cada función describe qué produce su output. Permite a agentes razonar sobre cadenas de composición (ej: prices → log_return → sharpe_ratio) sin leer código.
2.1 KiB
2.1 KiB
name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, params, output, tested, tests, test_file_path, file_path
| name | kind | lang | domain | version | purity | signature | description | tags | uses_functions | uses_types | returns | returns_optional | error_type | imports | params | output | tested | tests | test_file_path | file_path | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| cache_to_file | function | py | infra | 1.0.0 | impure | def cache_to_file(cache_dir: str, namespace: str = 'default') -> FileCache | Cache key-value donde cada entry es un archivo JSON en disco. Keys se hashean con SHA-256 para generar nombres de archivo seguros. Metadata (ttl, created_at, original_key) en sidecar .meta. Mejor que SQLite para valores grandes (PDFs procesados, embeddings). |
|
false | error_go_core |
|
|
instancia FileCache con metodos set, get, get_or_set, clear y stats | true |
|
python/functions/infra/cache_to_file_test.py | python/functions/infra/cache_to_file.py |
Ejemplo
from infra.cache_to_file import cache_to_file
store = cache_to_file("/tmp/my_cache", namespace="embeddings")
# Almacenar un embedding grande
store.set("doc:123", embedding_vector, ttl=86400)
# Recuperar
vec = store.get("doc:123")
# Factory pattern
result = store.get_or_set(
"pdf:page_42",
factory=lambda: extract_pdf_text("doc.pdf", page=42),
ttl=0, # sin expiracion
)
Estructura en disco
cache_dir/
namespace/
{sha256_key}.json # valor serializado como JSON
{sha256_key}.meta # {"created_at": ..., "expires_at": ..., "original_key": ...}
Notas
Cada entry genera exactamente dos archivos: .json para el valor y .meta para la metadata. La key original se guarda en .meta["original_key"] para facilitar debugging. Thread-safe mediante threading.Lock. La eviction es lazy: se verifica expires_at al hacer get.