cmd
def cmd(
name:str, vault_fn:functools._lru_cache_wrapper=vault
):Turn a Vault method into a plain function of the arguments a command line can give, keeping their descriptions.
vishalakshi command per vault method
The vishalakshi command runs vault methods from a shell, for example vishalakshi grab https://example.com/post or vishalakshi ask "why does late chunking help". CMDS lists the methods it offers. cmd turns each method into a subcommand. It builds the arguments of the subcommand from the signature of the method. vishalakshi search --help shows the same parameters and descriptions as the documentation. cmd leaves out arguments that cannot be typed on a command line. These are **kwargs, the stop and progress callbacks, stand-in chats and parameters with a callable default. Every command opens the same vault. That vault is the file that $VISHALAKSHI_VAULT names, or ~/.vishalakshi/vault.db when the variable is not set. $VISHALAKSHI_OFFLINE stops the vault from downloading a model. A result is printed as JSON. An answer is printed as prose with its citations.
Turn a Vault method into a plain function of the arguments a command line can give, keeping their descriptions.
The one vault every command uses: the file $VISHALAKSHI_VAULT names, else the default path.
Run the vishalakshi command; vishalakshi <cmd> --help describes any subcommand.
Print a result: an answer as prose with its citations, anything else as JSON.
Convert a value that json.dumps cannot encode: iterables become lists, numpy scalars become Python numbers, and anything else becomes a string.
usage: vishalakshi find [-h] [--limit LIMIT] [--kind KIND] q
Chunk-level hybrid search (FTS5 + vectors, RRF-fused), each hit carrying its breadcrumb.
positional arguments:
q query
options:
-h, --help show this help message and exit
--limit LIMIT hits to return (default: 10)
--kind KIND restrict to one or more KINDS ('note' or 'note,web')
args = p.parse_args(['late chunking', '--limit', '3', '--kind', 'note,web']).__dict__
test_eq(args['q'], 'late chunking'); test_eq(args['limit'], 3); test_eq(args['kind'], 'note,web')
test_eq(sorted(set(CMDS) - {m for m in dir(Vault) if not m.startswith('_')}), []) # every command is a real method
test_eq(json.loads(json.dumps(L(['a', 'b']), default=jsonable)), ['a', 'b']) # `L` is not a list; JSON needs telling
# a callable argument has no command-line spelling, so it is not offered as a flag
_ps = signature(cmd('ask')).parameters
assert 'chat' not in _ps and {'question', 'ref', 'model'} <= set(_ps), list(_ps)
assert {'suggest_noisy','mark_noisy','mark_pii','pii','accept_noisy'} <= set(CMDS)
assert {'level', 'set_level', 'set_floor', 'findings', 'send_check'} <= set(CMDS)
assert 'local_chat' not in signature(cmd('read_doc')).parameters