Skip to main content

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:

  1. Check if similar questions exist in the cache
  2. If found, show the cached answers
  3. 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)

Source distribution for llm-questioncache 0.1.0
File Size Uploaded
llm_questioncache-0.1.0.tar.gz 55.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for llm-questioncache 0.1.0
File Interpreter ABI Platform
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 log

Release 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

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page