openstax-llm
Pedagogical semantic chunking, RAG dataset preparation, and LLM fine-tuning pipelines from OpenStax textbooks.
This is the core library and CLI of the openstax-llm project. It transforms OpenStax college textbooks into structured, citation-aware, formula-safe datasets for vector search (RAG) and model fine-tuning.
If you want to drive this from an AI coding agent, see the sibling packages:
| Package | Purpose |
|---|---|
openstax-llm (this package) |
Library + openstax-llm CLI |
openstax-llm-mcp |
Model Context Protocol server |
skills/openstax-llm |
Agent skill with workflows and references |
Install
uv add openstax-llm
CLI
# Search the OpenStax catalog
openstax-llm search physics
# Inspect chunk statistics for a textbook
openstax-llm info astronomy-2e
# Compile and chunk a textbook into a JSONL dataset
openstax-llm prepare astronomy-2e -o datasets/astronomy-2e.jsonl
Library
from openstax_llm import DocumentChunker, TextBookDataset
chunker = DocumentChunker(target_words=400, max_words=600, overlap_words=50)
dataset = TextBookDataset.from_textbook("calculus-volume-1", chunker=chunker)
dataset.to_jsonl("calculus.jsonl")
print(dataset.summary())
DocumentChunker also works on arbitrary markdown, which is useful for tests and for
non-OpenStax sources:
from openstax_llm import DocumentChunker
chunks = DocumentChunker().chunk_markdown(
"## 1.2 Functions\n\nAn inline formula $f(x)=x^2$ stays intact.\n",
book_slug="my-notes",
section="1.2",
section_title="Functions",
)
Guarantees
- Formula integrity — a chunk boundary is never placed inside an unclosed
$...$or$$...$$block. - Pedagogical cohesion — worked examples, definitions, problem sets, and summaries are kept whole whenever they fit within
max_words. - Provenance — every chunk carries
book_slug,book_title,chapter,section,section_title, andchunk_type.
Chunk schema
| Field | Type | Description |
|---|---|---|
chunk_id |
string |
<section>-c<index>, e.g. 1.2-c003 |
text |
string |
Markdown with intact LaTeX math |
book_slug |
string |
Canonical OpenStax slug |
book_title |
string |
Human-readable title |
chapter |
string |
Chapter number from the section hierarchy |
section |
string |
Section number, e.g. 1.2 |
section_title |
string |
Module title |
chunk_type |
string |
prose, example, exercise, definition, summary |
word_count |
integer |
Whitespace-delimited word count |
token_est |
integer |
Heuristic estimate, words * 1.3 |
metadata |
object |
Extensible metadata for downstream indexes |
Development
This package lives in the openstax-llm uv workspace. Run every check from the repository root:
uv sync
uv run pytest -v
uv run ruff check . && uv run ruff format --check .
uv run mypy
License
MIT
Metadata
Release files for openstax-llm 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 | |
|---|---|---|---|
| openstax_llm-0.1.0.tar.gz | 17.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| openstax_llm-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 31.9 kB
Release files / openstax_llm-0.1.0.tar.gz
| Download URL | openstax_llm-0.1.0.tar.gz |
|---|---|
| Size | 17.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f5bd15ba1b45a6b98110048b5edfb4dd08b75f8534c7803367ae025aa0ee4567
|
|
BLAKE2b-256 checksum How to use checksums |
73f9bcb91e508c2fdce587a281edf3bd76379e453a727cf113488df2ae9ddeed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / openstax_llm-0.1.0-py3-none-any.whl
| Download URL | openstax_llm-0.1.0-py3-none-any.whl |
|---|---|
| Size | 14.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
12c8ea954a54b4195f859fbf28f599b3fb82ed60c7f6916eae0d172fb16fa75a
|
|
BLAKE2b-256 checksum How to use checksums |
17ab8d69fe16bbce9a8e699a33de5a8a958e251838c6313545d91ea7e271f4b6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|