Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/orbit-python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Orbit Python

on:
push:
branches: ['**']
paths: ['src/**', 'libs/**', 'Makefile', 'packages/python/**', '.github/workflows/orbit-python.yml']
pull_request:
paths: ['src/**', 'libs/**', 'Makefile', 'packages/python/**', '.github/workflows/orbit-python.yml']
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Build the extension
run: make extension
- name: Test orbit.memory
working-directory: packages/python
run: |
pip install pytest
PYTHONPATH=src python -m pytest tests -q
- name: Build the wheel (compiles from src/)
run: |
pip install build
python -m build --wheel packages/python
104 changes: 0 additions & 104 deletions .github/workflows/python-package.yml

This file was deleted.

6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,8 @@ CLAUDE.md
pubspec.lock
.flutter-plugins
.flutter-plugins-dependencies
packages/flutter/native_libraries/
packages/flutter/native_libraries/
# Python
__pycache__/
*.egg-info/
.pytest_cache/
31 changes: 28 additions & 3 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ SELECT vector_turboquant_backend();

**Description:**
Initializes the vector extension for a given table and column. This is **mandatory** before performing any vector search or quantization.
`vector_init` must be called in every database connection that needs to perform vector operations.
The options are persisted in `_sqliteai_vector` (only when they change), so other connections can run
`vector_full_scan` without calling `vector_init` again: the scan loads them. Calling it again in a
connection where the table is already registered only checks consistency, without querying the schema.

The target table must have a **`rowid`** (an integer primary key, either explicit or implicit).
If the table was created using `WITHOUT ROWID`, it must have **exactly one primary key column of type `INTEGER`**.
Expand Down Expand Up @@ -118,7 +120,11 @@ This ensures that each vector can be uniquely identified and efficiently referen
inner loop; the query vector is normalized once per scan, so the reported distances are
unchanged. It is an assertion, not a request: if the stored vectors are *not* unit
length the distances will be wrong. Quantized scans ignore it, because the quantized
index holds scaled integers whose norm is not 1. Default `0`.
index holds scaled integers whose norm is not 1. Works with `FLOAT32`, `FLOAT16` and
`FLOATB16`. Default `0`.
* `partition`: A column of the same table (letters, digits and `_`) that a `vector_full_scan`
can be restricted to (see below). The scan then reads only that partition's rows, through an
index on the column if there is one, instead of the whole table. Not supported by quantized scans.

**Example:**

Expand All @@ -127,6 +133,9 @@ SELECT vector_init('documents', 'embedding', 'dimension=384,type=FLOAT32,distanc

-- embeddings already normalized by the model: faster cosine, same results
SELECT vector_init('documents', 'embedding', 'dimension=384,type=FLOAT32,distance=cosine,normalized=1');

-- searches usually stay inside one conversation: let the scan read only its rows
SELECT vector_init('messages', 'embedding', 'dimension=384,type=FLOAT16,distance=cosine,normalized=1,partition=conversation');
```

---
Expand Down Expand Up @@ -257,7 +266,7 @@ INSERT INTO compressed_vectors(embedding) VALUES(vector_as_u8(X'010203'));

---

## 🔍 `vector_full_scan(table, column, vector [, k])`
## 🔍 `vector_full_scan(table, column, vector [, k [, partition]])`

**Returns:** `Virtual Table (rowid, distance)`

Expand All @@ -271,6 +280,9 @@ Since this interface only returns rowid and distance, if you need to access addi
* `column` (TEXT): Column containing vectors.
* `vector` (BLOB or JSON): The query vector.
* `k` (INTEGER, optional): Number of nearest neighbors to return. When provided, the module collects the top-k results sorted by distance. When omitted, the module operates in **streaming mode** — rows are returned progressively as they are scanned, enabling standard SQL clauses such as `WHERE` and `LIMIT` to control filtering and result count.
* `partition` (optional): Only rows whose `partition` column (declared in `vector_init`) equals this
value are scanned. In streaming mode, restrict with the hidden column instead: `WHERE v.part = ?`.
Measured with 100,000 rows in 200 partitions: one partition in 0.6–0.9 ms instead of ~45 ms.

**Examples:**

Expand All @@ -287,6 +299,19 @@ FROM vector_full_scan('documents', 'embedding', vector_as_f32('[0.1, 0.2, 0.3]')
LIMIT 5;
```

```sql
-- Top-k inside one partition (partition=conv in vector_init)
SELECT rowid, distance
FROM vector_full_scan('messages', 'embedding', vector_as_f32('[0.1, 0.2, 0.3]'), 5, 'chat-42');

-- Streaming inside one partition, with more filters applied by SQL
SELECT m.id, v.distance
FROM vector_full_scan('messages', 'embedding', vector_as_f32('[0.1, 0.2, 0.3]')) AS v
JOIN messages m ON m.id = v.rowid
WHERE v.part = 'chat-42' AND m.role = 'user'
ORDER BY v.distance LIMIT 5;
```

```sql
-- Streaming mode with JOIN and filtering
SELECT
Expand Down
71 changes: 71 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,77 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

### Added

- **`orbit` for Python, built from this repository.** `packages/python` is now the
`astrolle-orbit` package: it compiles the extension from `src/` and ships it inside the
wheel (`orbit/lib/`), instead of downloading prebuilt binaries. `orbit.load(conn)` loads it.
- **`orbit.memory`: conversational memory inside SQLite.** `add` chunks a message (≤ 450
characters, structured answers by their summary), embeds it with a function the caller
passes (Orbit loads no model) and stores it in `orbit_chunks` with its role, time and model.
`recall` finds what was said before: it strips the question's conversational wrapper, skips
the recent window, and only returns chunks that are very similar (≥ 0.5) or similar and
sharing content words (≥ 0.3) — cosine alone did not separate signal from noise.
`forget_conversation` and `missing_sources` (backfill) complete it. No runtime dependencies.
- **`python -m orbit.eval`: a memory evaluation set** of 102 questions in Spanish, English and
Portuguese (same conversation, names and figures, another language, another conversation, by
date, changed facts, and questions that must recall nothing). Baseline with
paraphrase-multilingual-MiniLM-L12-v2: 57/80 positives, 21/22 negatives clean; 0/10 across
conversations, 1/8 by date and 3/6 changed facts are the known gaps.
- **`packages/python/bench/bench_memory.py`**: search latency at realistic sizes. 20,000 chunks
in 50 conversations: ~10 ms median; 100,000 in 200: ~40 ms. Filtering by conversation does
not make it faster yet: the scan reads the whole table and filters afterwards.
- **CI for the Python package** (`orbit-python.yml`): builds the extension, runs the tests and
builds the wheel.
- **Hybrid recall.** An FTS5 index (`orbit_chunks_fts`, kept in sync by triggers, rebuilt for
chunks stored before it) is fused with the vector ranking by reciprocal rank fusion. A chunk
passes with similarity ≥ 0.6 on its own (was 0.5) or ≥ 0.3 with a full-text match. With 300
filler messages per conversation, positives go from 54/80 to 63/80 and clean negatives from
18/22 to 20/22; with none, 57→64/80 and 21/22.
- **Dates in words** (`orbit.dates`, es/en/pt): today, yesterday, last week, a weekday, "el martes
25", "November 25th", "no dia 24"… become a range in the caller's timezone (`recall(now=…)`).
They filter only questions about the conversation ("what did we talk about…"); otherwise a
relative date leaves the topic and an absolute one stays in it. By-date recall: 1/8 → 8/8.
- **Pairs.** Each recalled chunk carries `pair`: the answer to a question, or the question of an
answer.
- **`python -m orbit.eval --noise N`** adds filler messages, like a long real conversation, and
`--min-score`/`--min-score-with-words` to calibrate.
- **Partitions in `vector_full_scan`.** `vector_init(..., 'partition=<column>')` declares a column a
scan can be restricted to: as a 5th argument in top-k mode, or `WHERE v.part = ?` in streaming
mode. The scan's own SELECT then reads only that partition (through its index). One conversation
of 100,000 chunks in 200: ~45 ms → 0.6–0.9 ms. Quantized scans refuse it explicitly.
- **`vector_init` options are persisted** in `_sqliteai_vector` (only when they change) and a scan
in another connection loads them: `vector_init` is no longer needed per connection. Re-calling it
on a registered table returns before the three schema queries it used to run. Invalid persisted
rows are refused, not trusted.
- **`normalized=1` works with `FLOAT16` and `FLOATB16`** (the `1 - dot` shortcut on the existing
DOT kernels; the query is normalized in its own format).
- **`orbit.memory` stores FLOAT16 by default**: half the database (100,000 chunks: 210 → 108 MB),
identical recall in `orbit.eval`, and searches restricted to the conversation by partition.
Tables holding FLOAT32 vectors keep that format.

- **`orbit.facts`: what Orbit knows about a person, across conversations.** `might_hold_fact` decides
without a model whether a message could state a fact (a statement with a personal cue, a name or a
figure); only then `learn` asks the caller's model (`llm(system, user) -> str`, no provider in Orbit)
for facts under stable keys, in the message's language. A new fact replaces an active one with its
key only when both are about the same thing (similarity ≥ 0.45: the model reuses keys for unrelated
facts, measured 0.06–0.39 for different facts and 0.50–0.73 for the same one). `recall` searches
every conversation; `forget` deletes the fact, its older versions and the messages (and answers) it
came from. `python -m orbit.eval --facts`: across conversations 0/10 → 9.3/10, changed facts 3/6 →
4.7/6, positives 64/80 → 75.3/80 (3 runs), clean negatives unchanged (21/22).

### Fixed

- Every compiler warning (`-Wmisleading-indentation`, `-Wsign-compare`, `-Wstringop-overflow`).
- **A recall's `pair` is dropped when the caller already has it** (it is in the window, is the
question, or came back as a result of its own): nothing enters the prompt twice.

### Removed

- The upstream `sqliteai-vector` Python package, its binary downloader and its PyPI workflow.

## [1.2.0] - 2026-11-01

A read-through of the sources, followed by a security review of all of `src/`, turned up
Expand Down
Loading