sqlrite 0.1.10__tar.gz → 0.1.12__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. {sqlrite-0.1.10 → sqlrite-0.1.12}/Cargo.lock +5 -5
  2. {sqlrite-0.1.10 → sqlrite-0.1.12}/Cargo.toml +1 -1
  3. {sqlrite-0.1.10 → sqlrite-0.1.12}/PKG-INFO +1 -1
  4. {sqlrite-0.1.10 → sqlrite-0.1.12}/desktop/package.json +1 -1
  5. {sqlrite-0.1.10 → sqlrite-0.1.12}/docs/phase-7-plan.md +20 -10
  6. {sqlrite-0.1.10 → sqlrite-0.1.12}/docs/roadmap.md +3 -3
  7. {sqlrite-0.1.10 → sqlrite-0.1.12}/docs/supported-sql.md +22 -2
  8. {sqlrite-0.1.10 → sqlrite-0.1.12}/pyproject.toml +1 -1
  9. {sqlrite-0.1.10 → sqlrite-0.1.12}/sdk/python/Cargo.toml +1 -1
  10. {sqlrite-0.1.10 → sqlrite-0.1.12}/src/sql/executor.rs +673 -20
  11. {sqlrite-0.1.10 → sqlrite-0.1.12}/src/sql/mod.rs +130 -0
  12. {sqlrite-0.1.10 → sqlrite-0.1.12}/src/sql/parser/select.rs +15 -14
  13. {sqlrite-0.1.10 → sqlrite-0.1.12}/.github/workflows/ci.yml +0 -0
  14. {sqlrite-0.1.10 → sqlrite-0.1.12}/.github/workflows/release-pr.yml +0 -0
  15. {sqlrite-0.1.10 → sqlrite-0.1.12}/.github/workflows/release.yml +0 -0
  16. {sqlrite-0.1.10 → sqlrite-0.1.12}/.github/workflows/rust.yml +0 -0
  17. {sqlrite-0.1.10 → sqlrite-0.1.12}/.gitignore +0 -0
  18. {sqlrite-0.1.10 → sqlrite-0.1.12}/CODE_OF_CONDUCT.md +0 -0
  19. {sqlrite-0.1.10 → sqlrite-0.1.12}/LICENSE +0 -0
  20. {sqlrite-0.1.10 → sqlrite-0.1.12}/MAINTAINERS +0 -0
  21. {sqlrite-0.1.10 → sqlrite-0.1.12}/Makefile +0 -0
  22. {sqlrite-0.1.10 → sqlrite-0.1.12}/README.md +0 -0
  23. {sqlrite-0.1.10 → sqlrite-0.1.12}/desktop/index.html +0 -0
  24. {sqlrite-0.1.10 → sqlrite-0.1.12}/desktop/package-lock.json +0 -0
  25. {sqlrite-0.1.10 → sqlrite-0.1.12}/desktop/src/App.svelte +0 -0
  26. {sqlrite-0.1.10 → sqlrite-0.1.12}/desktop/src/app.css +0 -0
  27. {sqlrite-0.1.10 → sqlrite-0.1.12}/desktop/src/main.ts +0 -0
  28. {sqlrite-0.1.10 → sqlrite-0.1.12}/desktop/src/vite-env.d.ts +0 -0
  29. {sqlrite-0.1.10 → sqlrite-0.1.12}/desktop/svelte.config.js +0 -0
  30. {sqlrite-0.1.10 → sqlrite-0.1.12}/desktop/tsconfig.json +0 -0
  31. {sqlrite-0.1.10 → sqlrite-0.1.12}/desktop/vite.config.ts +0 -0
  32. {sqlrite-0.1.10 → sqlrite-0.1.12}/docs/_index.md +0 -0
  33. {sqlrite-0.1.10 → sqlrite-0.1.12}/docs/architecture.md +0 -0
  34. {sqlrite-0.1.10 → sqlrite-0.1.12}/docs/design-decisions.md +0 -0
  35. {sqlrite-0.1.10 → sqlrite-0.1.12}/docs/desktop.md +0 -0
  36. {sqlrite-0.1.10 → sqlrite-0.1.12}/docs/embedding.md +0 -0
  37. {sqlrite-0.1.10 → sqlrite-0.1.12}/docs/file-format.md +0 -0
  38. {sqlrite-0.1.10 → sqlrite-0.1.12}/docs/getting-started.md +0 -0
  39. {sqlrite-0.1.10 → sqlrite-0.1.12}/docs/pager.md +0 -0
  40. {sqlrite-0.1.10 → sqlrite-0.1.12}/docs/release-plan.md +0 -0
  41. {sqlrite-0.1.10 → sqlrite-0.1.12}/docs/release-secrets.md +0 -0
  42. {sqlrite-0.1.10 → sqlrite-0.1.12}/docs/smoke-test.md +0 -0
  43. {sqlrite-0.1.10 → sqlrite-0.1.12}/docs/sql-engine.md +0 -0
  44. {sqlrite-0.1.10 → sqlrite-0.1.12}/docs/storage-model.md +0 -0
  45. {sqlrite-0.1.10 → sqlrite-0.1.12}/docs/usage.md +0 -0
  46. {sqlrite-0.1.10 → sqlrite-0.1.12}/examples/README.md +0 -0
  47. {sqlrite-0.1.10 → sqlrite-0.1.12}/examples/c/Makefile +0 -0
  48. {sqlrite-0.1.10 → sqlrite-0.1.12}/examples/c/hello.c +0 -0
  49. {sqlrite-0.1.10 → sqlrite-0.1.12}/examples/go/go.mod +0 -0
  50. {sqlrite-0.1.10 → sqlrite-0.1.12}/examples/go/hello.go +0 -0
  51. {sqlrite-0.1.10 → sqlrite-0.1.12}/examples/nodejs/hello.mjs +0 -0
  52. {sqlrite-0.1.10 → sqlrite-0.1.12}/examples/python/hello.py +0 -0
  53. {sqlrite-0.1.10 → sqlrite-0.1.12}/examples/rust/quickstart.rs +0 -0
  54. {sqlrite-0.1.10 → sqlrite-0.1.12}/examples/wasm/Makefile +0 -0
  55. {sqlrite-0.1.10 → sqlrite-0.1.12}/examples/wasm/index.html +0 -0
  56. {sqlrite-0.1.10 → sqlrite-0.1.12}/images/SQLRite - Desktop.png +0 -0
  57. {sqlrite-0.1.10 → sqlrite-0.1.12}/images/SQLRite Data Structures.png +0 -0
  58. {sqlrite-0.1.10 → sqlrite-0.1.12}/images/SQLRite Simple SQL Execution High Level Diagram.png +0 -0
  59. {sqlrite-0.1.10 → sqlrite-0.1.12}/images/SQLRite Simple SQL INSERT Execution High Level Diagram (Insert Row).png +0 -0
  60. {sqlrite-0.1.10 → sqlrite-0.1.12}/images/SQLRite Simple SQL INSERT Execution High Level Diagram.png +0 -0
  61. {sqlrite-0.1.10 → sqlrite-0.1.12}/images/SQLRite_logo.png +0 -0
  62. {sqlrite-0.1.10 → sqlrite-0.1.12}/images/architecture.png +0 -0
  63. {sqlrite-0.1.10 → sqlrite-0.1.12}/rust-toolchain.toml +0 -0
  64. {sqlrite-0.1.10 → sqlrite-0.1.12}/samples/AST.delete.example +0 -0
  65. {sqlrite-0.1.10 → sqlrite-0.1.12}/samples/AST.insert.exemple +0 -0
  66. {sqlrite-0.1.10 → sqlrite-0.1.12}/samples/AST.select.example +0 -0
  67. {sqlrite-0.1.10 → sqlrite-0.1.12}/samples/AST.update.example +0 -0
  68. {sqlrite-0.1.10 → sqlrite-0.1.12}/samples/CREATE TABLE sqlrite_schema.sql +0 -0
  69. {sqlrite-0.1.10 → sqlrite-0.1.12}/samples/CREATE_TABLE with duplicate.sql +0 -0
  70. {sqlrite-0.1.10 → sqlrite-0.1.12}/samples/CREATE_TABLE.sql +0 -0
  71. {sqlrite-0.1.10 → sqlrite-0.1.12}/samples/INSERT.sql +0 -0
  72. {sqlrite-0.1.10 → sqlrite-0.1.12}/scripts/bump-version.sh +0 -0
  73. {sqlrite-0.1.10 → sqlrite-0.1.12}/sdk/go/README.md +0 -0
  74. {sqlrite-0.1.10 → sqlrite-0.1.12}/sdk/go/conn.go +0 -0
  75. {sqlrite-0.1.10 → sqlrite-0.1.12}/sdk/go/go.mod +0 -0
  76. {sqlrite-0.1.10 → sqlrite-0.1.12}/sdk/go/rows.go +0 -0
  77. {sqlrite-0.1.10 → sqlrite-0.1.12}/sdk/go/sqlrite.go +0 -0
  78. {sqlrite-0.1.10 → sqlrite-0.1.12}/sdk/go/sqlrite_test.go +0 -0
  79. {sqlrite-0.1.10 → sqlrite-0.1.12}/sdk/go/stmt.go +0 -0
  80. {sqlrite-0.1.10 → sqlrite-0.1.12}/sdk/python/README.md +0 -0
  81. {sqlrite-0.1.10 → sqlrite-0.1.12}/sdk/python/src/lib.rs +0 -0
  82. {sqlrite-0.1.10 → sqlrite-0.1.12}/sdk/python/tests/test_sqlrite.py +0 -0
  83. {sqlrite-0.1.10 → sqlrite-0.1.12}/src/connection.rs +0 -0
  84. {sqlrite-0.1.10 → sqlrite-0.1.12}/src/error.rs +0 -0
  85. {sqlrite-0.1.10 → sqlrite-0.1.12}/src/lib.rs +0 -0
  86. {sqlrite-0.1.10 → sqlrite-0.1.12}/src/main.rs +0 -0
  87. {sqlrite-0.1.10 → sqlrite-0.1.12}/src/meta_command/mod.rs +0 -0
  88. {sqlrite-0.1.10 → sqlrite-0.1.12}/src/repl/mod.rs +0 -0
  89. {sqlrite-0.1.10 → sqlrite-0.1.12}/src/sql/db/database.rs +0 -0
  90. {sqlrite-0.1.10 → sqlrite-0.1.12}/src/sql/db/mod.rs +0 -0
  91. {sqlrite-0.1.10 → sqlrite-0.1.12}/src/sql/db/secondary_index.rs +0 -0
  92. {sqlrite-0.1.10 → sqlrite-0.1.12}/src/sql/db/table.rs +0 -0
  93. {sqlrite-0.1.10 → sqlrite-0.1.12}/src/sql/pager/cell.rs +0 -0
  94. {sqlrite-0.1.10 → sqlrite-0.1.12}/src/sql/pager/file.rs +0 -0
  95. {sqlrite-0.1.10 → sqlrite-0.1.12}/src/sql/pager/header.rs +0 -0
  96. {sqlrite-0.1.10 → sqlrite-0.1.12}/src/sql/pager/index_cell.rs +0 -0
  97. {sqlrite-0.1.10 → sqlrite-0.1.12}/src/sql/pager/interior_page.rs +0 -0
  98. {sqlrite-0.1.10 → sqlrite-0.1.12}/src/sql/pager/mod.rs +0 -0
  99. {sqlrite-0.1.10 → sqlrite-0.1.12}/src/sql/pager/overflow.rs +0 -0
  100. {sqlrite-0.1.10 → sqlrite-0.1.12}/src/sql/pager/page.rs +0 -0
  101. {sqlrite-0.1.10 → sqlrite-0.1.12}/src/sql/pager/pager.rs +0 -0
  102. {sqlrite-0.1.10 → sqlrite-0.1.12}/src/sql/pager/table_page.rs +0 -0
  103. {sqlrite-0.1.10 → sqlrite-0.1.12}/src/sql/pager/varint.rs +0 -0
  104. {sqlrite-0.1.10 → sqlrite-0.1.12}/src/sql/pager/wal.rs +0 -0
  105. {sqlrite-0.1.10 → sqlrite-0.1.12}/src/sql/parser/create.rs +0 -0
  106. {sqlrite-0.1.10 → sqlrite-0.1.12}/src/sql/parser/insert.rs +0 -0
  107. {sqlrite-0.1.10 → sqlrite-0.1.12}/src/sql/parser/mod.rs +0 -0
  108. {sqlrite-0.1.10 → sqlrite-0.1.12}/src/sql/tokenizer.rs +0 -0
@@ -3736,7 +3736,7 @@ dependencies = [
3736
3736
 
3737
3737
  [[package]]
3738
3738
  name = "sqlrite-desktop"
3739
- version = "0.1.10"
3739
+ version = "0.1.12"
3740
3740
  dependencies = [
3741
3741
  "serde",
3742
3742
  "serde_json",
@@ -3748,7 +3748,7 @@ dependencies = [
3748
3748
 
3749
3749
  [[package]]
3750
3750
  name = "sqlrite-engine"
3751
- version = "0.1.10"
3751
+ version = "0.1.12"
3752
3752
  dependencies = [
3753
3753
  "clap",
3754
3754
  "env_logger",
@@ -3763,7 +3763,7 @@ dependencies = [
3763
3763
 
3764
3764
  [[package]]
3765
3765
  name = "sqlrite-ffi"
3766
- version = "0.1.10"
3766
+ version = "0.1.12"
3767
3767
  dependencies = [
3768
3768
  "cbindgen",
3769
3769
  "sqlrite-engine",
@@ -3771,7 +3771,7 @@ dependencies = [
3771
3771
 
3772
3772
  [[package]]
3773
3773
  name = "sqlrite-nodejs"
3774
- version = "0.1.10"
3774
+ version = "0.1.12"
3775
3775
  dependencies = [
3776
3776
  "napi",
3777
3777
  "napi-build",
@@ -3781,7 +3781,7 @@ dependencies = [
3781
3781
 
3782
3782
  [[package]]
3783
3783
  name = "sqlrite-python"
3784
- version = "0.1.10"
3784
+ version = "0.1.12"
3785
3785
  dependencies = [
3786
3786
  "pyo3",
3787
3787
  "sqlrite-engine",
@@ -27,7 +27,7 @@ resolver = "3"
27
27
  # `package =` key so the import name stays `sqlrite` internally:
28
28
  # sqlrite = { package = "sqlrite-engine", path = "…" }
29
29
  name = "sqlrite-engine"
30
- version = "0.1.10"
30
+ version = "0.1.12"
31
31
  authors = ["Joao Henrique Machado Silva <joaoh82@gmail.com>"]
32
32
  edition = "2024"
33
33
  rust-version = "1.85"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlrite
3
- Version: 0.1.10
3
+ Version: 0.1.12
4
4
  Classifier: Development Status :: 3 - Alpha
5
5
  Classifier: Intended Audience :: Developers
6
6
  Classifier: License :: OSI Approved :: MIT License
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "sqlrite-desktop-frontend",
3
3
  "private": true,
4
- "version": "0.1.10",
4
+ "version": "0.1.12",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
@@ -106,24 +106,33 @@ SELECT id, title FROM docs ORDER BY embedding <-> [0.1, ...] LIMIT 10;
106
106
  - `<=>` → `vec_distance_cosine`
107
107
  - `<#>` → `vec_distance_dot`
108
108
 
109
+ > **Scope correction (2026-04-27, during 7b implementation):** Operators turned out to be a much bigger parser change than Q6 anticipated. sqlparser-rs (current pinned version) **fails outright** on `<->` and `<#>` ("Expected: an expression, found: ->"). Only `<=>` parses, as MySQL's `Spaceship` (null-safe equality). Supporting all three operators requires either a fork of sqlparser to extend the SQLite dialect, or a string-preprocessing pass that rewrites operators to function calls before handing SQL to the parser — neither is the "tiny parser change" Q6 estimated.
110
+ >
111
+ > **Decision:** ship 7b with **functions only**. Operators are deferred to a follow-up sub-phase **7b.1**. The KNN use case (`ORDER BY vec_distance_l2(col, [...]) LIMIT k`) still works — just verbose. When 7b.1 lands, queries can switch from function-call form to operator form without any other behavior change.
112
+
109
113
  **Decisions:**
110
114
 
111
115
  - **Dispatch in the existing expression evaluator.** No new function-registration framework — these are built-in functions like `||` is.
112
- - **Operators land in the parser as new infix tokens.** sqlparser's SQLite dialect doesn't have these; we either extend the dialect or post-process the AST. Either is fine.
116
+ - **Operators land in 7b.1, not 7b.** See scope-correction note above.
117
+ - **`ORDER BY` widened to accept arbitrary expressions** as part of 7b. Pre-7b, the parser restricted ORDER BY to bare column refs; without expression support, KNN queries would have been impossible. New shape: `eval_expr` is called per-row to produce sort keys. This is a strict superset — `ORDER BY col` still works because `Expr::Identifier` takes the same path.
113
118
 
114
- **LOC estimate:** ~250 lines.
119
+ **LOC estimate:** ~250 lines for the functions; another ~50 for the ORDER BY parser extension. Total ~300 LOC, slightly over Q-time estimate.
115
120
 
116
121
  **Tests:** all three distance metrics against hand-computed values; operator parsing; KNN result ordering.
117
122
 
118
123
  ---
119
124
 
120
- ### 7c — Brute-force KNN executor optimization
125
+ ### 7c — Brute-force KNN executor optimization
126
+
127
+ **What shipped.** The SELECT executor now branches on `(ORDER BY, LIMIT k)` shape. When both are present and `k < N`, the new `select_topk` function maintains a bounded `BinaryHeap` of size k instead of full-sorting all N rowids. O(N log k) instead of O(N log N).
128
+
129
+ **Implementation note: max-heap with direction-aware Ord.** A single `HeapEntry { key: Value, rowid: i64, asc: bool }` wrapper handles both `ORDER BY ASC LIMIT k` (k smallest) and `ORDER BY DESC LIMIT k` (k largest) without separate code paths. The `asc` flag inverts the natural Ord, so the displacement test reduces to "new entry < heap top" in both cases. After the scan, `into_sorted_vec` returns the right caller-facing order (ascending for ASC, descending for DESC).
121
130
 
122
- **What.** Recognize the pattern `ORDER BY <distance-expr> LIMIT k` and execute it with a bounded min-heap (size k) instead of a full sort. O(N log k) instead of O(N log N).
131
+ **Measured speedup** (N=10k, k=10, single REAL column sort key, release build): ~1.8×. The advantage scales with N and with per-row work KNN queries where the sort key is `vec_distance_l2(col, [...])` benefit much more because each key evaluation is itself O(dim).
123
132
 
124
- **Why a separate sub-phase.** 7b makes it work; 7c makes it fast enough to be useful on millions of rows. Worth shipping as its own commit so the perf delta is visible in benchmarks.
133
+ **LOC**: ~120 implementation + ~180 tests/benchmark = ~300 total. Slightly over the ~150 estimate because the test surface (correctness + bench + edge cases for k=0, k>N, empty input, distance-function integration) ended up larger than initially projected.
125
134
 
126
- **LOC estimate:** ~150 lines including a tiny benchmark to prove the speedup.
135
+ **Pre-existing bug surfaced.** The seed function for the benchmark needed positive scores because the INSERT parser doesn't currently handle `Expr::UnaryOp(Minus, Number(...))` for negative literals. Worked around with a Knuth-hash scrambler that stays positive; the underlying parser bug is documented as a follow-up.
127
136
 
128
137
  ---
129
138
 
@@ -296,10 +305,11 @@ let rows = conn.execute(&resp.sql)?;
296
305
  ## Implementation order + dependencies
297
306
 
298
307
  ```
299
- 7a (VECTOR type) — independent, foundational
300
- └── 7b (distances) — needs 7a
301
- └── 7c (KNN exec) — needs 7b
302
- └── 7d (HNSW)— needs 7b/7c
308
+ 7a (VECTOR type) — independent, foundational
309
+ └── 7b (distance functions) — needs 7a
310
+ └── 7b.1 (operators) — sugar over 7b; deferred from 7b per scope correction
311
+ └── 7c (KNN exec opt) — needs 7b (operators not required)
312
+ └── 7d (HNSW) — needs 7b/7c
303
313
 
304
314
  7e (JSON) — independent, can interleave anywhere
305
315
 
@@ -470,9 +470,9 @@ The full plan + recorded design decisions live in [`docs/phase-7-plan.md`](phase
470
470
 
471
471
  Approved sub-phases (Q1–Q10 resolved):
472
472
 
473
- - **7a — `VECTOR(N)` column type** — dense fixed-dimension f32 storage via the existing cell encoding; bump file format to v4. Bracket-array literal syntax `[0.1, 0.2, …]` (Q7).
474
- - **7b — Distance functions + KNN operators** — `vec_distance_l2/cosine/dot` plus pgvector-style `<->` `<=>` `<#>` operators (Q6).
475
- - **7c — Brute-force KNN executor optimization** — recognize `ORDER BY <distance> LIMIT k`, use bounded min-heap.
473
+ - **✅ 7a — `VECTOR(N)` column type** *(v0.1.10)* — dense fixed-dimension f32 storage via the existing cell encoding; format bumped to v4. Bracket-array literal syntax `[0.1, 0.2, …]` (Q7).
474
+ - **✅ 7b — Distance functions** *(v0.1.11)* — `vec_distance_l2/cosine/dot`, plus the ORDER BY-expressions parser change so KNN queries work end-to-end. Operators (`<->` `<=>` `<#>`) deferred to **7b.1** — sqlparser doesn't parse them natively, contradicting Q6's "tiny parser change" assumption.
475
+ - **✅ 7c — Brute-force KNN executor optimization** — bounded `BinaryHeap` of size k for `ORDER BY <expr> LIMIT k`. ~1.8× faster than full-sort at N=10k for cheap keys; bigger gains on expensive keys like `vec_distance_l2`.
476
476
  - **7d — HNSW ANN index** — `CREATE INDEX … USING hnsw (col)`; persisted as cell-encoded graph. Fixed defaults `M=16, ef_construction=200, ef_search=50` (Q2).
477
477
  - **7e — JSON column type + path queries** — `JSON` data type stored as bincoded `serde_json::Value` (Q3); `json_extract` / `json_array_length` / `json_object_keys` / `json_type`.
478
478
  - **7f — ~~Full-text search with BM25~~** — **deferred to Phase 8** (Q1).
@@ -125,7 +125,7 @@ FROM <table>
125
125
 
126
126
  - **Projection**: `*` (all columns in declaration order) or a bare column list. Columns not declared on the table are rejected.
127
127
  - **`WHERE`**: any [expression](#expressions). Evaluated per row; NULL-as-false in WHERE context (three-valued logic collapsed to two-valued for filtering).
128
- - **`ORDER BY`**: single column, `ASC` (default) or `DESC`. Sort key types must match; mixing `INTEGER` and `TEXT` across rows under a single `ORDER BY` is a runtime error.
128
+ - **`ORDER BY`**: single sort key, `ASC` (default) or `DESC`. The sort key can be a bare column reference OR any expression — including function calls — so KNN queries like `ORDER BY vec_distance_l2(embedding, [...]) LIMIT k` work end-to-end *(Phase 7b)*. Sort key types must match; mixing `INTEGER` and `TEXT` across rows under a single `ORDER BY` is a runtime error.
129
129
  - **`LIMIT`**: non-negative integer literal. `LIMIT 0` is valid (returns zero rows).
130
130
 
131
131
  ### Index probing
@@ -140,7 +140,7 @@ The executor includes a tiny optimizer: if the `WHERE` is exactly `<indexed_col>
140
140
  - **`DISTINCT`**
141
141
  - **`LIKE`**, **`IN`**, **`IS NULL`** / **`IS NOT NULL`**, `BETWEEN`
142
142
  - **Expressions in the projection list** (`SELECT age + 1 FROM users`) — projection is bare column references only
143
- - **Multi-column `ORDER BY`**, `NULLS FIRST/LAST`
143
+ - **Multi-column `ORDER BY`**, `NULLS FIRST/LAST` (single sort key only; the sort key itself can be an expression as of Phase 7b)
144
144
  - **`OFFSET`**
145
145
  - **Column aliases** (`SELECT name AS n FROM users`)
146
146
 
@@ -196,6 +196,26 @@ Expressions work inside `WHERE` (both in `SELECT`, `UPDATE`, `DELETE`) and on th
196
196
 
197
197
  Same set accepted by `INSERT` (see [Value literals accepted](#value-literals-accepted)).
198
198
 
199
+ ### Built-in functions
200
+
201
+ | Function | Returns | Notes |
202
+ |---|---|---|
203
+ | `vec_distance_l2(a, b)` | Real (f64) | Euclidean distance √Σ(aᵢ−bᵢ)². Smaller is closer. *(Phase 7b)* |
204
+ | `vec_distance_cosine(a, b)` | Real (f64) | Cosine distance `1 − (a·b) / (‖a‖·‖b‖)`. Errors on zero-magnitude vectors (cosine is undefined). Smaller is closer; identical vectors return 0.0, orthogonal vectors return 1.0. *(Phase 7b)* |
205
+ | `vec_distance_dot(a, b)` | Real (f64) | Negated dot product `−(a·b)`. Negation makes "smaller is closer" consistent with the others. For unit-norm vectors equals `vec_distance_cosine(a, b) - 1`. *(Phase 7b)* |
206
+
207
+ All three vector-distance functions take exactly two arguments, both of which must be vectors of the same dimension. Either argument can be a column reference (`embedding`), a bracket-array literal (`[0.1, 0.2, 0.3]`), or any sub-expression that evaluates to a vector. Mismatched dimensions error with `vector dimensions don't match (lhs=N, rhs=M)`.
208
+
209
+ The KNN ranking pattern that motivates this set:
210
+
211
+ ```sql
212
+ SELECT id, title FROM docs
213
+ ORDER BY vec_distance_l2(embedding, [0.1, 0.2, ..., 0.0])
214
+ LIMIT 10;
215
+ ```
216
+
217
+ > **Operator forms (`<->` `<=>` `<#>`) are not supported yet.** They're the de facto pgvector convention but blocked on a sqlparser limitation — will land as a Phase 7b.1 follow-up. Use the function-call form for now.
218
+
199
219
  ### Type coercion in arithmetic
200
220
 
201
221
  - **Integer-only ops stay integer.** `1 + 2` → `3` (Integer).
@@ -4,7 +4,7 @@ build-backend = "maturin"
4
4
 
5
5
  [project]
6
6
  name = "sqlrite"
7
- version = "0.1.10"
7
+ version = "0.1.12"
8
8
  description = "Python bindings for SQLRite — a small, embeddable SQLite clone written in Rust."
9
9
  authors = [{ name = "Joao Henrique Machado Silva", email = "joaoh82@gmail.com" }]
10
10
  license = { text = "MIT" }
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "sqlrite-python"
3
- version = "0.1.10"
3
+ version = "0.1.12"
4
4
  authors = ["Joao Henrique Machado Silva <joaoh82@gmail.com>"]
5
5
  edition = "2024"
6
6
  rust-version = "1.85"