sql
triplum.store.sql ¶
SQL-backed stores through SQLAlchemy/SQLModel.
SQLAlchemyStore ¶
SQLAlchemyStore(
url: str = "sqlite://",
*,
text: BM25Settings | None = None,
)
Bases: RecordStore, TextSearchStore
Records in the database at url (any SQLAlchemy URL); missing tables are created.
The default URL is an in-memory SQLite database, private to this store instance and shared by all threads using it. Backend-specific stores may subclass this where specific SQL is faster.
Source code in src/triplum/store/sql/generic.py
28 29 30 31 32 33 34 35 36 37 38 39 40 | |
engine
instance-attribute
¶
engine = create_engine(
url,
poolclass=StaticPool,
connect_args={"check_same_thread": False},
)
index_text ¶
index_text(collection_id: UUID, /) -> None
Replace this collection's search snapshot only after a successful build.
Source code in src/triplum/store/sql/generic.py
42 43 44 45 46 47 48 | |
search_text ¶
search_text(
query: str,
/,
*,
collection_id: UUID,
viewer: Viewer | None = None,
k: int,
) -> list[RetrievalHit]
Search the last built snapshot; see TextSearchStore for the contract.
Source code in src/triplum/store/sql/generic.py
50 51 52 53 54 55 56 | |
add_sources ¶
add_sources(
sources: Iterable[Source], /, *, allow: Iterable[str]
) -> None
Source code in src/triplum/store/sql/generic.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
replace_chunks ¶
replace_chunks(
source_id: UUID, chunks: Iterable[Chunk], /
) -> None
Source code in src/triplum/store/sql/generic.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
source ¶
Source code in src/triplum/store/sql/generic.py
123 124 125 126 127 128 129 130 | |
sources ¶
Source code in src/triplum/store/sql/generic.py
132 133 134 135 136 137 138 | |
chunks ¶
Source code in src/triplum/store/sql/generic.py
140 141 142 143 144 145 146 147 | |
close ¶
close() -> None
Close this store's database connections. An in-memory database is discarded.
Source code in src/triplum/store/sql/generic.py
149 150 151 | |
FTS5Settings ¶
Bases: FingerprintedDataModel
FTS5 tokenizer declaration and the pattern extracting literal OR query terms.
FTS5 fixes BM25's k1=1.2 and b=0.75. The default tokenizer retains accents and underscores, closer to the reference's lowercased Unicode word tokens.
Attributes:
| Name | Type | Description |
|---|---|---|
tokenizer |
str
|
|
token_pattern |
str
|
|
SQLiteStore ¶
SQLiteStore(
url: str = "sqlite://",
*,
text: FTS5Settings | None = None,
)
Bases: SQLAlchemyStore
SQLite records with persisted FTS5 search snapshots and backend-specific settings.
Source code in src/triplum/store/sql/sqlite.py
32 33 34 35 36 37 38 39 40 | |
index_text ¶
index_text(collection_id: UUID, /) -> None
Atomically replace a collection's FTS5 table and its recorded settings.
Source code in src/triplum/store/sql/sqlite.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
search_text ¶
search_text(
query: str,
/,
*,
collection_id: UUID,
viewer: Viewer | None = None,
k: int,
) -> list[RetrievalHit]
Search the persisted snapshot, checking settings and filtering before top-k.
Source code in src/triplum/store/sql/sqlite.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |