Sixty-three comments said what the next statement already said: # Connect to LanceDB above connect_lancedb, # Path object above isinstance(source, Path), # Get page numbers from provenance above the prov loop, # Clear and populate results above list_view.clear(). They cost a read and carry nothing. The line is whether a comment restates one statement or labels a phase. Phase labels stay: the migrations keep # Create staging table with new schema and # Copy from staging to final table in batches, each heading ten lines of a long procedure. So do comments carrying a fact the code cannot: the merge_insert update-only note on document_meta, why the poller builds sources eagerly, why create_document_from_source returns a list for directories, that indexes need training data, the field-group markers in the config models, and the file:// URL-encoding note in create_document_from_source. capabilities/ is untouched. Its docstrings sit next to prompt surface, and changing them needs an eval to back it. The cassette-recording docs were wrong three ways. They named tests/test_qa.py::test_qa_anthropic, which no longer exists; they targeted whole modules, so a rewrite would re-record cassettes for services the recorder is not running; and they used COHERE_API_KEY where the SDK reads CO_API_KEY. docs/development.md now names exact tests with -n0, and the keyed example is test_cohere_reranker, which owns the one cassette recording api.cohere.com.
55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
import logging
|
|
import warnings
|
|
|
|
from rich.console import Console
|
|
from rich.logging import RichHandler
|
|
|
|
|
|
def get_logger() -> logging.Logger:
|
|
"""Return the library logger configured with a Rich handler."""
|
|
logger = logging.getLogger("haiku.rag")
|
|
|
|
handler = RichHandler(
|
|
console=Console(stderr=True),
|
|
rich_tracebacks=True,
|
|
)
|
|
formatter = logging.Formatter("%(message)s")
|
|
handler.setFormatter(formatter)
|
|
|
|
logger.setLevel(logging.INFO)
|
|
|
|
# Remove any existing handlers to avoid duplicates on reconfiguration
|
|
for hdlr in logger.handlers[:]:
|
|
logger.removeHandler(hdlr)
|
|
|
|
logger.addHandler(handler)
|
|
# Do not let messages propagate to the root logger
|
|
logger.propagate = False
|
|
return logger
|
|
|
|
|
|
def configure_cli_logging(level: int = logging.INFO) -> logging.Logger:
|
|
"""Configure logging for CLI runs.
|
|
|
|
- Silence ALL non-haiku.rag loggers by detaching root handlers and setting
|
|
their level to ERROR.
|
|
- Attach a Rich handler only to the "haiku.rag" logger.
|
|
- Prevent propagation so only our logger prints in the CLI.
|
|
"""
|
|
# Silence root logger completely
|
|
root = logging.getLogger()
|
|
for hdlr in root.handlers[:]:
|
|
root.removeHandler(hdlr)
|
|
root.setLevel(logging.ERROR)
|
|
|
|
# Optionally silence some commonly noisy libraries explicitly as a safeguard
|
|
for noisy in ("httpx", "httpcore", "docling", "urllib3", "asyncio"):
|
|
logging.getLogger(noisy).setLevel(logging.ERROR)
|
|
logging.getLogger(noisy).propagate = False
|
|
|
|
logger = get_logger()
|
|
logger.setLevel(level)
|
|
logger.propagate = False
|
|
|
|
warnings.filterwarnings("ignore")
|
|
return logger
|