• Stefy Lanza (nextime / spora )'s avatar
    embeddings: chunk against the model's REAL window, and report it everywhere (v0.3.74) · bd855536
    Stefy Lanza (nextime / spora ) authored
    Two gaps in 0.3.72/73, both of which left chunking looking enabled while doing
    nothing useful.
    
    THE THRESHOLD WAS A NUMBER SOMEONE TYPED.
    
        max_len = int(_emb_cfg.get('n_ctx') or _raw.get('n_ctx') or 8192)
    
    Set n_ctx above what the model accepts and the windows are built too big; the
    tokenizer then truncates each window at its real limit anyway and chunking
    silently stops protecting anything -- the same invisible loss this code exists
    to remove, reached through a config typo instead of a missing feature. The
    window is now min(configured, tokenizer.model_max_length), with one trap
    handled: HuggingFace sets model_max_length to a sentinel near 1e30 when the
    checkpoint declares none, and believing that means never chunking at all, so a
    value that large is read as "unknown" and the caller's number stands. Same clamp
    on the sentence-transformers path, taking the smaller of max_seq_length and the
    tokenizer's own limit.
    
    THE MULTI-VECTOR PATH COLLECTED THE COUNTS AND DROPPED THEM. It builds its own
    response, so the dense path's report did not cover it -- chunking was invisible
    on exactly the path that needs it most, which is the bug this feature was
    written to fix. It now reports
    
        "chunked": {"windows": [...], "pool": ..., "token_limit": N}
    
    and logs the limit with the merges applied. `token_limit` is deliberate: it is
    what makes a WRONG n_ctx visible rather than merely ineffective.
    
    46 tests. Suite at the 25 pre-existing failures.
    Co-Authored-By: 's avatarClaude Opus 5 <noreply@anthropic.com>
    Claude-Session: https://claude.ai/code/session_01HXRMe9ZPUQCCCtBai9uqt3
    bd855536
test_embed_long_input.py 15.9 KB