Skip to content

Enable FTS5 in SQLite #694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 11, 2025
Merged

Enable FTS5 in SQLite #694

merged 3 commits into from
Jul 11, 2025

Conversation

zanieb
Copy link
Member

@zanieb zanieb commented Jul 10, 2025

No description provided.

@zanieb zanieb added platform:linux Specific to the Linux platform python:3.13 labels Jul 10, 2025
@zanieb zanieb mentioned this pull request Jul 10, 2025
Copy link
Collaborator

@geofft geofft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, should we add a test for this? The one I came up with is

$ uvx python@3.14b4
Python 3.14.0b4 (main, Jul  8 2025, 21:00:06) [Clang 20.1.4 ] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> s = sqlite3.connect(":memory:")
>>> c = s.cursor()
>>> c.execute("CREATE VIRTUAL TABLE email USING fts5(sender, title, body);")
Traceback (most recent call last):
  File "<python-input-3>", line 1, in <module>
    c.execute("CREATE VIRTUAL TABLE email USING fts5(sender, title, body);")
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sqlite3.OperationalError: no such module: fts5

@geofft
Copy link
Collaborator

geofft commented Jul 10, 2025

$ cat test.py
import sqlite3
s = sqlite3.connect(":memory:")
c = s.cursor()
c.execute("PRAGMA compile_options;")
for [opt] in c.fetchall():
  print(opt)
$ diff <(uvx python@3.14b3 test.py) <(uvx python@3.14b4 test.py)
21,23d20
< ENABLE_FTS4
< ENABLE_FTS5
< ENABLE_GEOPOLY
25d21
< ENABLE_RTREE
32c28
< MAX_FUNCTION_ARG=127
---
> MAX_FUNCTION_ARG=1000

Should we care about these other extensions too?

@zanieb
Copy link
Member Author

zanieb commented Jul 10, 2025

Yeah it makes sense to enable anything that's common in the wild. A test seems reasonable, do you want to add it?

@geofft
Copy link
Collaborator

geofft commented Jul 10, 2025

Looks like there's some tests already. Since this is my first time actually running them, I'm going to let CI chew on this to make sure the tests fail on the full matrix, and then I'll push the #defines to fix it.

@groksrc
Copy link

groksrc commented Jul 11, 2025

We could really use this fix, our project is broken without fts5.

basicmachines-co/basic-memory#225
basicmachines-co/basic-memory#221

@phernandez
Copy link

To add more context, I'm running on OS X and fts5 is currently broken, as of a couple days ago

sqlite_test.py

#!/usr/bin/env -S uv run -vv --script

import sys

print(".".join(map(str, sys.version_info[:3])))

help('modules sqlite3')

import sqlite3
# Connect to the database
conn = sqlite3.connect(':memory')
cur = conn.cursor()

cur.execute('pragma compile_options;')
available_pragmas = cur.fetchall()
conn.close()

print(available_pragmas)

if ('ENABLE_FTS5',) in available_pragmas:
    print('YES')
else:
    print('NO')

output:

➜  dev uv --version
uv 0.7.20 (251420396 2025-07-09)
➜  dev ./sqlite_test.py
DEBUG uv 0.7.20 (251420396 2025-07-09)
DEBUG No project found; searching for Python interpreter
DEBUG No Python version file found in ancestors of working directory: /Users/phernandez/dev
DEBUG Searching for default Python interpreter in virtual environments, managed installations, or search path
DEBUG Failed to inspect Python interpreter from virtual environment at `/Users/phernandez/bin/python3`
TRACE Skipping missing interpreter at /Users/phernandez/bin/python3
DEBUG Searching for managed installations at `/Users/phernandez/.local/share/uv/python`
DEBUG Found managed installation `cpython-3.13.5-macos-aarch64-none`
TRACE Found cached interpreter info for Python 3.13.5, skipping query of: /Users/phernandez/.local/share/uv/python/cpython-3.13.5-macos-aarch64-none/bin/python3.13
DEBUG Found `cpython-3.13.5-macos-aarch64-none` at `/Users/phernandez/.local/share/uv/python/cpython-3.13.5-macos-aarch64-none/bin/python3.13` (managed installations)
DEBUG Using Python 3.13.5 interpreter at: /Users/phernandez/.local/share/uv/python/cpython-3.13.5-macos-aarch64-none/bin/python3.13
DEBUG Running `python ./sqlite_test.py`
DEBUG Spawned child 13899 in process group 13898
3.13.5

Here is a list of modules whose name or summary contains 'sqlite3'.
If there are any, enter a module name to get more help.

_sqlite3
dbm.sqlite3
sqlite3 - The sqlite3 extension module provides a DB-API 2.0 (PEP 249) compliant
sqlite3.__main__ - A simple SQLite CLI for the sqlite3 module.
sqlite3.dbapi2
sqlite3.dump

[('ATOMIC_INTRINSICS=1',), ('COMPILER=clang-20.1.4',), ('DEFAULT_AUTOVACUUM',), ('DEFAULT_CACHE_SIZE=-2000',), ('DEFAULT_FILE_FORMAT=4',), ('DEFAULT_JOURNAL_SIZE_LIMIT=-1',), ('DEFAULT_MMAP_SIZE=0',), ('DEFAULT_PAGE_SIZE=4096',), ('DEFAULT_PCACHE_INITSZ=20',), ('DEFAULT_RECURSIVE_TRIGGERS',), ('DEFAULT_SECTOR_SIZE=4096',), ('DEFAULT_SYNCHRONOUS=2',), ('DEFAULT_WAL_AUTOCHECKPOINT=1000',), ('DEFAULT_WAL_SYNCHRONOUS=2',), ('DEFAULT_WORKER_THREADS=0',), ('DIRECT_OVERFLOW_READ',), ('ENABLE_DBSTAT_VTAB',), ('ENABLE_FTS3',), ('ENABLE_FTS3_PARENTHESIS',), ('ENABLE_FTS3_TOKENIZER',), ('ENABLE_MATH_FUNCTIONS',), ('MALLOC_SOFT_LIMIT=1024',), ('MAX_ATTACHED=10',), ('MAX_COLUMN=2000',), ('MAX_COMPOUND_SELECT=500',), ('MAX_DEFAULT_PAGE_SIZE=8192',), ('MAX_EXPR_DEPTH=1000',), ('MAX_FUNCTION_ARG=1000',), ('MAX_LENGTH=1000000000',), ('MAX_LIKE_PATTERN_LENGTH=50000',), ('MAX_MMAP_SIZE=0x7fff0000',), ('MAX_PAGE_COUNT=0xfffffffe',), ('MAX_PAGE_SIZE=65536',), ('MAX_SQL_LENGTH=1000000000',), ('MAX_TRIGGER_DEPTH=1000',), ('MAX_VARIABLE_NUMBER=32766',), ('MAX_VDBE_OP=250000000',), ('MAX_WORKER_THREADS=8',), ('MUTEX_PTHREADS',), ('SYSTEM_MALLOC',), ('TEMP_STORE=1',), ('THREADSAFE=1',)]
NO
DEBUG Command exited with code: 0

@geofft geofft removed platform:darwin Specific to the macOS platform platform:linux Specific to the Linux platform python:3.13 labels Jul 11, 2025
@geofft geofft merged commit 7797c38 into main Jul 11, 2025
108 checks passed
@geofft geofft deleted the zb/fts5 branch July 11, 2025 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants