Isabelle Semantic Embedding
Project description
Isabelle Semantic Embedding
This library provides semantic search for Isabelle: it allows users retrieve, in natural language, the semantically closest entities — including constants, theorems, theorem collections (so-called named_theorems), types, type classes, locales, and tactics.
The process consists of two stages: semantic interpretation and embedding. In the interpretation stage, a Claude/Codex agent automatically explains each entity in an Isabelle theory into plain English and stores the obtained English explanations in a database. In the embedding stage, an embedding model (typically an LLM of several billion parameters) embeds each explanation into a vector (usually a few thousand dimensions), which is likewise stored in the local database. At query time, the user's natural-language query is embedded into a vector by the same model. The system then ranks all stored entity vectors by their cosine similarity to the query vector and returns the top $k$ — the entities whose explanations are closest to the query under the model's semantic encoding.
1. Installation
This library ships as part of the Isabelle-AI package. If you already have Isabelle-AI installed, no further installation is needed; otherwise:
conda create -n <YOUR_ENV> -c https://conda.qiyuan.me -c conda-forge isabelle-ai
Note: this system currently supports Isabelle 2025-2 only. Installing without the conda manager is possible, but is an expert-only path: detailed documentation is not ready for now; the author suggests asking Claude/Codex to work out a standalone installation.
2. Quick start
This library is not normally used directly. A typical entry point is AoA.
3. Fetching the prebuilt database
The author provides pre-computed semantic interpretations, together with their Qwen3-8B embeddings, covering part of Isabelle/HOL 2025-2 and afp-2026-05-13. Download them for immediate use with the following bash/powershell commands:
conda activate <YOUR_ENV>
isabelle-semantics pull # download the prebuilt database and merge it into the local DB
isabelle-semantics status # compare the local database against the prebuilt one
Note: complete pre-computed interpretations of the AFP, together with the exact afp-2026-05-13 version they correspond to, will be published soon; this section will be updated accordingly.
4. Running semantic interpretation on your own theories
The prebuilt database covers only part of Isabelle/HOL and afp-2026-05-13. To interpret and embed your own theories, use the run_semantic_interpretation command:
theory My_Wonderful_Theory
imports "Semantic_Embedding.Semantic_Embedding" (* DONT'T FORGET ME ;-) *)
Some_Wonderful_Dependencies
begin
(* A lot of wonderful formalizations here *)
run_semantic_interpretation (* interpret and embed the current theory and its ancestors *)
run_semantic_interpretation Theory_Name1 Theory_Name2 (* interpret and embed exactly these two theories, not My_Wonderful_Theory itself *)
end
Be aware that interpretation and embedding together can take a long time; please let the run finish. If you do interrupt it, most intermediate results are saved, and the next run resumes rather than starting from scratch.
5. Configuring the embedding provider
By default, the system uses Claude Code with claude-opus-4-8[1m] for semantic interpretation, and Qwen/Qwen3-Embedding-8B for embedding. A Codex-based interpreter, along with the ability to switch the interpretation LLM, is under development.
The embedding model can be changed through three settings — the driver, the endpoint, and the model name:
declare [[Semantic_Embedding.embedding_driver = "OpenAI_Embedding_Provider", (* most embedding providers speak the OpenAI-compatible protocol, so you will rarely need to change this *)
Semantic_Embedding.embedding_base_url = "https://api.fireworks.ai/inference",
Semantic_Embedding.embedding_model = "Qwen/Qwen3-Embedding-8B"]]
Alternatively, the same three settings can be given as environment variables in $(isabelle getenv -b ISABELLE_HOME_USER)/etc/settings:
EMBEDDING_DRIVER=...
EMBEDDING_BASE_URL=...
EMBEDDING_MODEL=...
The Isabelle options take precedence: an environment variable is consulted only where the corresponding option is unset.
If you self-host an embedding model (e.g. via vLLM or TGI), set embedding_base_url to your server's address and embedding_model to the model name it serves.
The system guarantees that the query and the stored entities are embedded by the same model. If you change embedding_model, all contextual entities will therefore be re-embedded with the new model before the next semantic search — this typically costs little. Changing only embedding_base_url while keeping embedding_model unchanged triggers no re-embedding.
The following subsections cover each configuration option and its available choices in turn.
5.1 embedding_driver
Two drivers are currently available:
OpenAI_Embedding_Provider(default) — speaks to any OpenAI-compatible /v1/embeddings endpoint: Fireworks, OpenAI, Mistral, Aliyun DashScope, ….Gemini_Embedding— the native Google Gemini API.
5.2 embedding_base_url
The endpoint the embedding driver contacts, given without a /v1 suffix (the driver appends /v1/embeddings itself). Examples:
https://api.fireworks.ai/inference(default)https://api.openai.comhttps://api.mistral.ai
5.3 embedding_model
The canonical model name — the HuggingFace name where one exists, else the provider's model id. The following are configured out of the box:
| Canonical name | Endpoint |
|---|---|
Qwen/Qwen3-Embedding-8B (default) |
Fireworks |
harrier-oss-v1-27b, llama-nv-embed-reasoning-3b |
Fireworks |
text-embedding-3-large, text-embedding-3-small |
OpenAI |
codestral-embed |
Mistral |
gemini-embedding-2-preview |
Gemini |
Other models can be added through the embedding config file (§7.1).
5.4 API key
The embedding API key is read from the single environment variable EMBEDDING_API_KEY, whatever the endpoint. Add the line
EMBEDDING_API_KEY=...
to $(isabelle getenv -b ISABELLE_HOME_USER)/etc/settings, then restart Isabelle.
The Gemini_Embedding driver additionally falls back to GEMINI_API_KEY.
6. The database
All data lives in the following directory:
| OS | Database directory |
|---|---|
| Linux | ~/.cache/Isabelle_Semantic_Embedding |
| macOS | ~/Library/Caches/Isabelle_Semantic_Embedding |
| Windows | C:\Users\<USER NAME>\AppData\Local\Qiyuan\Isabelle_Semantic_Embedding\Cache |
The directory consists of the semantic database (semantics.lmdb), one vector store per embedding model (vector_<model>.lmdb), and local caches.
Warning: the system uses LMDB for its semantic and vector stores, and LMDB on a networked filesystem (NFS, Lustre) can corrupt silently. On compute clusters that use network filesystems, it is highly recommended to relocate the semantic database to a local disk by adding the line
SEMANTIC_DB_DIR=<PATH_ON_A_LOCAL_DISK>
to $(isabelle getenv -b ISABELLE_HOME_USER)/etc/settings. After changing this setting,
fully restart Isabelle. With RPC_Host unset (the default since Isabelle_RPC 0.4.0), the
RPC host is a per-session attached process that dies with its Isabelle automatically
and inherits the restarted Isabelle's environment — restarting Isabelle is all it takes.
If you run a shared external host (you set RPC_Host and started the host
yourself), you must kill and relaunch it too. Kill it however you started it:
- a daemon launched via
Isabelle_RPC_Host.fork_and_launch__():pkill -f 'Isabelle_RPC_Host\.fork_and_launch__' - a host started with the
isabelle-rpc-hostconsole script:pkill -f isabelle-rpc-host - a foreground host (e.g.
debug_launcher.py): just Ctrl-C it.
(None of these patterns match the per-session attached hosts, whose command line says
run_attached__ — those need no manual cleanup.)
Then relaunch it so that the host's own process environment carries the new
SEMANTIC_DB_DIR: the host reads it from os.environ only, and a plain shell does not
source etc/settings. Either export it in the launching shell, or launch through
Isabelle's environment, e.g.:
isabelle env isabelle-rpc-host 127.0.0.1:27182 /tmp/rpc.log
Update checks. At most once a week, the library probes the prebuilt database with a single HEAD request, and prints a notice when a newer version exists. It never downloads anything on its own — updating is always an explicit isabelle-semantics pull. The check can be turned off by setting
SEMANTIC_EMBEDDING_AUTO_UPDATE=false
in $(isabelle getenv -b ISABELLE_HOME_USER)/etc/settings
7. Technical details
7.1 The embedding config file
To use a new embedding model or a new provider endpoint, you must supply the following settings in $(isabelle getenv -b ISABELLE_HOME_USER)/etc/embedding_config:
dimension— the vector dimension, required for every model in use;normalize— whether to L2-normalize the vectors the endpoint returns (defaultfalse). Needed when the endpoint does not return unit vectors.max_request_size— the maximum number of texts sent in one embedding request batch (default 2048). Some endpoints enforce hard caps (e.g. Aliyun DashScope allows only 10)default_scores— the fallback similarity scores{score, local}given to entities that have no embedding vector yet.scorefor ordinary entities,localfor entities local to the current proof context. Default:{0.0, 0.0}.templates,task_description— templates, task_description — the model-specific prompts that instruction-aware embedding models expect around queries and documents; see the model card for the convention.providers.<domain>.normalization— maps the canonical model name (i.e., the name seen in HugginFace) to the id that the endpoint expects;providers.<domain>.batch— its presence enables the OpenAI-style Batch API for that endpoint.
The bundled template is an example.
7.2 Excluding entities from retrieval
Some entities are internal infrastructure: they are not meant to be used outside their own formalization, and therefore should not surface in search results. Built-in heuristics already exclude most of them (hidden names, datatype/record internals, …); to mark more by hand:
declare [[infra_constant Foo.bar]] (* a constant; cascades to theorems mentioning it *)
declare [[infra_type Foo.t]] (* a type *)
declare some_lemma[infra_thm] (* a theorem *)
declare [[infra_constant del Foo.bar]] (* del undoes any of the above *)
7.3 Reranker
A reranking stage after the vector search is implemented (option Semantic_Embedding.reranker_model) but disabled by default and currently unused: in our measurements it actually harms the retrieval performance.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file isabelle_semantic_embedding-0.2.0-cp311-abi3-win_amd64.whl.
File metadata
- Download URL: isabelle_semantic_embedding-0.2.0-cp311-abi3-win_amd64.whl
- Upload date:
- Size: 206.5 kB
- Tags: CPython 3.11+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
38e70d6be51c00c47c7eb20259a8d6ed224bcab055d5f9433f19fa288b210494
|
|
| MD5 |
f230aefbdb667cdc6260f25808d25ddf
|
|
| BLAKE2b-256 |
427ee8900588415f257d49fd12ead75c115400aa942f531433d0727200d53792
|
Provenance
The following attestation bundles were made for isabelle_semantic_embedding-0.2.0-cp311-abi3-win_amd64.whl:
Publisher:
wheels.yml on xqyww123/Isabelle_Semantic_Embedding
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
isabelle_semantic_embedding-0.2.0-cp311-abi3-win_amd64.whl -
Subject digest:
38e70d6be51c00c47c7eb20259a8d6ed224bcab055d5f9433f19fa288b210494 - Sigstore transparency entry: 2216709472
- Sigstore integration time:
-
Permalink:
xqyww123/Isabelle_Semantic_Embedding@384e06b83646e6b5bbce35fdd137598831ee32da -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/xqyww123
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
wheels.yml@384e06b83646e6b5bbce35fdd137598831ee32da -
Trigger Event:
push
-
Statement type:
File details
Details for the file isabelle_semantic_embedding-0.2.0-cp311-abi3-manylinux_2_17_x86_64.whl.
File metadata
- Download URL: isabelle_semantic_embedding-0.2.0-cp311-abi3-manylinux_2_17_x86_64.whl
- Upload date:
- Size: 177.5 kB
- Tags: CPython 3.11+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b07ebc676594841615b0a34a38f3e1c71588c5053c6f7a28032cc08b2a95797
|
|
| MD5 |
c3d21316beeb0a5e1855f9f8f863c733
|
|
| BLAKE2b-256 |
49c3aa4f91497ef28a3cc3b577f2bb39dfcd46c91feb3180f0243e8dbc0e5aa9
|
Provenance
The following attestation bundles were made for isabelle_semantic_embedding-0.2.0-cp311-abi3-manylinux_2_17_x86_64.whl:
Publisher:
wheels.yml on xqyww123/Isabelle_Semantic_Embedding
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
isabelle_semantic_embedding-0.2.0-cp311-abi3-manylinux_2_17_x86_64.whl -
Subject digest:
5b07ebc676594841615b0a34a38f3e1c71588c5053c6f7a28032cc08b2a95797 - Sigstore transparency entry: 2216710267
- Sigstore integration time:
-
Permalink:
xqyww123/Isabelle_Semantic_Embedding@384e06b83646e6b5bbce35fdd137598831ee32da -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/xqyww123
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
wheels.yml@384e06b83646e6b5bbce35fdd137598831ee32da -
Trigger Event:
push
-
Statement type:
File details
Details for the file isabelle_semantic_embedding-0.2.0-cp311-abi3-manylinux_2_17_aarch64.whl.
File metadata
- Download URL: isabelle_semantic_embedding-0.2.0-cp311-abi3-manylinux_2_17_aarch64.whl
- Upload date:
- Size: 178.2 kB
- Tags: CPython 3.11+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1930ccf4a4bc6498393d3c42e4e13c4eca06f6d5ebd433ec5c808289bb6c01b2
|
|
| MD5 |
a42ea92473c60615ad881ec7ee7de48c
|
|
| BLAKE2b-256 |
5c925f492709e9f26fd2e47edf57552ee5f6de710b4e7cac438601fe0924064a
|
Provenance
The following attestation bundles were made for isabelle_semantic_embedding-0.2.0-cp311-abi3-manylinux_2_17_aarch64.whl:
Publisher:
wheels.yml on xqyww123/Isabelle_Semantic_Embedding
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
isabelle_semantic_embedding-0.2.0-cp311-abi3-manylinux_2_17_aarch64.whl -
Subject digest:
1930ccf4a4bc6498393d3c42e4e13c4eca06f6d5ebd433ec5c808289bb6c01b2 - Sigstore transparency entry: 2216708389
- Sigstore integration time:
-
Permalink:
xqyww123/Isabelle_Semantic_Embedding@384e06b83646e6b5bbce35fdd137598831ee32da -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/xqyww123
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
wheels.yml@384e06b83646e6b5bbce35fdd137598831ee32da -
Trigger Event:
push
-
Statement type:
File details
Details for the file isabelle_semantic_embedding-0.2.0-cp311-abi3-macosx_11_0_universal2.whl.
File metadata
- Download URL: isabelle_semantic_embedding-0.2.0-cp311-abi3-macosx_11_0_universal2.whl
- Upload date:
- Size: 181.6 kB
- Tags: CPython 3.11+, macOS 11.0+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b770b3ffc119271bf9d570a1d137bc8260ee8e18410a1e3baa9ae25e2f532328
|
|
| MD5 |
2d20b6e0240d20531598280741d9d673
|
|
| BLAKE2b-256 |
e7196423260647879a7d8f98d15e89db821c571e24bc218f1c5996cb0c6a33bf
|
Provenance
The following attestation bundles were made for isabelle_semantic_embedding-0.2.0-cp311-abi3-macosx_11_0_universal2.whl:
Publisher:
wheels.yml on xqyww123/Isabelle_Semantic_Embedding
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
isabelle_semantic_embedding-0.2.0-cp311-abi3-macosx_11_0_universal2.whl -
Subject digest:
b770b3ffc119271bf9d570a1d137bc8260ee8e18410a1e3baa9ae25e2f532328 - Sigstore transparency entry: 2216708842
- Sigstore integration time:
-
Permalink:
xqyww123/Isabelle_Semantic_Embedding@384e06b83646e6b5bbce35fdd137598831ee32da -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/xqyww123
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
wheels.yml@384e06b83646e6b5bbce35fdd137598831ee32da -
Trigger Event:
push
-
Statement type: