llm-questioncache
A plugin for llm for sending questions to LLMs and getting succinct answers. It also saves answers in a SQLite database along with embeddings of the corresponding questions and will answer future, similar questions from the cache rather than the LLM.
Installation
llm install llm-questioncache
Usage
The plugin adds a new questioncache command group to llm. See llm questioncache --help for the full list of subcommands.
Ask a Question
llm questioncache ask "What is the capital of France?"
This will:
- Check if similar questions exist in the cache
- If found, show the cached answers
- If not found, ask the LLM and cache the response
You can also pipe questions through stdin:
echo "What is the capital of France?" | llm questioncache ask -
Send Last Question Directly to LLM
To bypass the cache and send the last asked question directly to the LLM:
llm questioncache send
You might have to do this if you've previously asked a similar-but-distinct question
Import Previous Answers
You can import a collection of previous questions and answers from a JSON file:
llm questioncache importanswers answers.json
The JSON file should contain an array of objects with question and answer fields.
If you've been using LLM in this way already you might have some useful answers already.
To retrieve and format all the LLM responses with a particular system prompt, use sqlite-utils:
uvx sqlite-utils "$(llm logs path)" "select prompt as question, response as answer from responses where system = 'Answer in as few words as possible. Use a brief style with short replies.'"
Clear the Cache
To delete all cached questions and answers:
llm questioncache clearcache
Configuration
The plugin uses your default LLM and embedding models as configured in llm. No additional configuration is required.
Key parameters (configured in the code):
- Relevance cutoff for similar questions: 0.8
- Number of similar answers to show: 3
- System prompt for brief answers: "Answer in as few words as possible. Use a brief style with short replies."
Shell integration
You might find it useful to create a shell script to succinctly invoke llm questioncache:
For example, save this as ~/.local/bin/q:
#!/usr/bin/env sh
llm questioncache $*
You can now pose questions with:
q how do you exit vim
Metadata
Release files for llm-questioncache 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| llm_questioncache-0.1.0.tar.gz | 55.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| llm_questioncache-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 64.5 kB
Release files / llm_questioncache-0.1.0.tar.gz
| Download URL | llm_questioncache-0.1.0.tar.gz |
|---|---|
| Size | 55.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
97432c9a7e6a692270349e1d3ec9bf6d2afcea2bb0dada9674dbbc76d36b5efe
|
|
BLAKE2b-256 checksum How to use checksums |
a4b27125ed36f7917934ee5eeab5af52b0b28b8526f267febbbf5a4e9e51153d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 9, 2025.
Transparency logRelease files / llm_questioncache-0.1.0-py3-none-any.whl
| Download URL | llm_questioncache-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3eb26c029130557c482b59dd0611c31d2622fc6c37e3f7cd83e52bcf1a316ded
|
|
BLAKE2b-256 checksum How to use checksums |
2e29fce71afd222eb738f697dc3e61b4f1c751f04db3025d043b2065d39ec1a7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 9, 2025.
Transparency log