relvector 0.1.0__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.
- relvector-0.1.0/.gitignore +40 -0
- relvector-0.1.0/CHANGELOG.md +25 -0
- relvector-0.1.0/LICENSE +202 -0
- relvector-0.1.0/PKG-INFO +189 -0
- relvector-0.1.0/README.md +150 -0
- relvector-0.1.0/THIRD_PARTY_NOTICES.md +54 -0
- relvector-0.1.0/docs/relvector/architecture.md +138 -0
- relvector-0.1.0/examples/relvector/orders_shipments.py +97 -0
- relvector-0.1.0/pyproject.toml +85 -0
- relvector-0.1.0/src/relvector/__init__.py +48 -0
- relvector-0.1.0/src/relvector/_version.py +1 -0
- relvector-0.1.0/src/relvector/api.py +187 -0
- relvector-0.1.0/src/relvector/embeddings.py +146 -0
- relvector-0.1.0/src/relvector/errors.py +31 -0
- relvector-0.1.0/src/relvector/extraction.py +141 -0
- relvector-0.1.0/src/relvector/indexing.py +138 -0
- relvector-0.1.0/src/relvector/integrations/__init__.py +1 -0
- relvector-0.1.0/src/relvector/integrations/sqlguard.py +33 -0
- relvector-0.1.0/src/relvector/mapping.py +405 -0
- relvector-0.1.0/src/relvector/py.typed +0 -0
- relvector-0.1.0/src/relvector/schema.py +130 -0
- relvector-0.1.0/src/relvector/store.py +410 -0
- relvector-0.1.0/tests/relvector/conftest.py +39 -0
- relvector-0.1.0/tests/relvector/test_postgres.py +192 -0
- relvector-0.1.0/tests/relvector/test_relvector.py +388 -0
- relvector-0.1.0/tests/relvector/test_search.py +139 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
build/
|
|
6
|
+
dist/
|
|
7
|
+
.eggs/
|
|
8
|
+
# Environments
|
|
9
|
+
.venv/
|
|
10
|
+
.venvs/
|
|
11
|
+
venv/
|
|
12
|
+
# Tooling caches
|
|
13
|
+
.pytest_cache/
|
|
14
|
+
.mypy_cache/
|
|
15
|
+
.ruff_cache/
|
|
16
|
+
.hypothesis/
|
|
17
|
+
.coverage
|
|
18
|
+
.coverage.*
|
|
19
|
+
coverage.xml
|
|
20
|
+
htmlcov/
|
|
21
|
+
# Local artefacts
|
|
22
|
+
/results/
|
|
23
|
+
*.sqlite3
|
|
24
|
+
*.db
|
|
25
|
+
.pgdata/
|
|
26
|
+
.env
|
|
27
|
+
.env.*
|
|
28
|
+
!.env.example
|
|
29
|
+
audit*.jsonl
|
|
30
|
+
.pytest_tmp/
|
|
31
|
+
|
|
32
|
+
# Static demo build output and download cache
|
|
33
|
+
/.cache/
|
|
34
|
+
/site/
|
|
35
|
+
|
|
36
|
+
# RelVector local indexes and example output
|
|
37
|
+
*.rvindex
|
|
38
|
+
*.rvindex-*
|
|
39
|
+
relvector_index.sqlite*
|
|
40
|
+
examples/relvector/_output/
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes are listed here. The project follows semantic versioning once released.
|
|
4
|
+
|
|
5
|
+
## 0.1.0 (2026-10-25)
|
|
6
|
+
|
|
7
|
+
First public release:
|
|
8
|
+
|
|
9
|
+
* Read-only connections for SQLite (`mode=ro`) and PostgreSQL (read-only `REPEATABLE READ`
|
|
10
|
+
transactions).
|
|
11
|
+
* Schema inspection: tables, columns, primary keys and foreign keys.
|
|
12
|
+
* Entity mappings with one-hop related tables, explicit `Include(via=...)` joins,
|
|
13
|
+
sensitive-field blocking, exclusions and deterministic templates.
|
|
14
|
+
* Bounded keyset extraction with per-relation `IN` queries and `ROW_NUMBER()` caps that report
|
|
15
|
+
truncation.
|
|
16
|
+
* Embedding providers: local sentence-transformers and dependency-free hashing.
|
|
17
|
+
* A persistent SQLite vector store with exact cosine search and metadata filters.
|
|
18
|
+
* Idempotent re-indexing with content hashes, pruning of deleted rows, atomic per-batch
|
|
19
|
+
checkpoints, typed checkpoint keys (date, datetime, UUID, Decimal), resume, and single-writer
|
|
20
|
+
ownership (`RunSupersededError`).
|
|
21
|
+
* Optional SQLGuard Ninja validation of extraction queries.
|
|
22
|
+
* Streaming exact search: chunked cursor reads, a bounded top-k heap, SQL-side filtering and
|
|
23
|
+
deterministic tie-breaking. Search memory no longer grows with index size
|
|
24
|
+
(`LocalVectorStore(search_chunk_size=...)`).
|
|
25
|
+
* PostgreSQL validation tests on a disposable database.
|
relvector-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
relvector-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: relvector
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Schema-aware semantic indexes over existing relational databases, with source references back to the rows.
|
|
5
|
+
Project-URL: Homepage, https://github.com/Pratik653/RelVector
|
|
6
|
+
Project-URL: Issues, https://github.com/Pratik653/RelVector/issues
|
|
7
|
+
Project-URL: Changelog, https://github.com/Pratik653/RelVector/blob/main/CHANGELOG.md
|
|
8
|
+
Author: RelVector contributors
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
License-File: THIRD_PARTY_NOTICES.md
|
|
12
|
+
Keywords: database,embeddings,rag,semantic-search,sql,sqlalchemy,vector-index
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Database
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Python: >=3.11
|
|
23
|
+
Requires-Dist: numpy>=1.26
|
|
24
|
+
Requires-Dist: sqlalchemy<3.0,>=2.0
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: build>=1.2; extra == 'dev'
|
|
27
|
+
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
28
|
+
Requires-Dist: psycopg[binary]>=3.1; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
30
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
31
|
+
Requires-Dist: sqlguard-ninja<0.8,>=0.7; extra == 'dev'
|
|
32
|
+
Provides-Extra: local
|
|
33
|
+
Requires-Dist: sentence-transformers>=2.3; extra == 'local'
|
|
34
|
+
Provides-Extra: postgres
|
|
35
|
+
Requires-Dist: psycopg[binary]>=3.1; extra == 'postgres'
|
|
36
|
+
Provides-Extra: sqlguard
|
|
37
|
+
Requires-Dist: sqlguard-ninja<0.8,>=0.7; extra == 'sqlguard'
|
|
38
|
+
Description-Content-Type: text/markdown
|
|
39
|
+
|
|
40
|
+
# RelVector
|
|
41
|
+
|
|
42
|
+
**Schema-aware semantic indexes over existing relational databases.**
|
|
43
|
+
|
|
44
|
+
RelVector makes selected relational data semantically searchable without migrating or
|
|
45
|
+
modifying the source database. It reads your schema, follows declared foreign keys, turns each
|
|
46
|
+
root row plus its related rows into deterministic, readable text, embeds it with a
|
|
47
|
+
pluggable provider and stores the vectors in a persistent local index. Every search result
|
|
48
|
+
points back to the exact source rows.
|
|
49
|
+
|
|
50
|
+
RelVector does **not** convert a database into a vector database. The database stays the
|
|
51
|
+
authoritative source and is only ever read.
|
|
52
|
+
|
|
53
|
+
> Status: `0.1.0`, alpha. Tested with SQLite and PostgreSQL 16. APIs may change before 1.0.
|
|
54
|
+
|
|
55
|
+
## Install
|
|
56
|
+
|
|
57
|
+
Python 3.11+:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pip install relvector # core: SQLAlchemy + NumPy
|
|
61
|
+
pip install "relvector[local]" # + sentence-transformers for local embeddings (pulls in PyTorch)
|
|
62
|
+
pip install "relvector[postgres]" # + psycopg 3; use postgresql+psycopg://user@host/db URLs
|
|
63
|
+
pip install "relvector[sqlguard]" # + optional SQLGuard Ninja query validation
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
For development, use `pip install -e ".[dev]"` from a checkout.
|
|
67
|
+
|
|
68
|
+
## Quick start
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from relvector import RelVector
|
|
72
|
+
|
|
73
|
+
with RelVector("sqlite:///shop.db", embedding_provider="local",
|
|
74
|
+
index_path="shop.rvindex") as rv:
|
|
75
|
+
print(rv.inspect_schema().describe()) # tables, columns, PKs, foreign keys
|
|
76
|
+
|
|
77
|
+
rv.configure(
|
|
78
|
+
root_table="orders", # one semantic record per order
|
|
79
|
+
include_tables=["shipments"], # joined via the declared foreign key
|
|
80
|
+
text_fields=["orders.status", "shipments.delay_reason"], # embedded
|
|
81
|
+
metadata_fields=["orders.status"], # stored and filterable, not embedded
|
|
82
|
+
exclude_fields=["customers.email"],
|
|
83
|
+
templates={
|
|
84
|
+
"orders": "Order {id} is {status}.",
|
|
85
|
+
"shipments": "Its associated shipment has a {delay_reason}.",
|
|
86
|
+
},
|
|
87
|
+
)
|
|
88
|
+
stats = rv.index(batch_size=500)
|
|
89
|
+
print(stats) # rows, embedded, unchanged, deleted, timings, rows/s
|
|
90
|
+
|
|
91
|
+
for hit in rv.search("orders delayed because of transport problems", top_k=5):
|
|
92
|
+
print(hit.score, hit.source_table, hit.source_pk, hit.references)
|
|
93
|
+
print(hit.text)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
The record for order 1002 reads:
|
|
97
|
+
`Order 1002 is delayed. Its associated shipment has a carrier capacity shortage.`
|
|
98
|
+
|
|
99
|
+
Runnable example: [examples/relvector/orders_shipments.py](examples/relvector/orders_shipments.py)
|
|
100
|
+
(`--provider hashing` runs without any model).
|
|
101
|
+
|
|
102
|
+
## How it works
|
|
103
|
+
|
|
104
|
+
| Stage | Behaviour |
|
|
105
|
+
|---|---|
|
|
106
|
+
| Inspect | SQLAlchemy inspector: tables, columns, primary keys, declared foreign keys. Catalog only, no rows. |
|
|
107
|
+
| Map | `EntityMapping`: root table, directly related tables (FK or explicit `Include(via=...)`), `text_fields`, `metadata_fields`, `exclude_fields`. Only listed columns are ever selected. |
|
|
108
|
+
| Extract | Keyset pagination on the primary key (`WHERE pk > :last ORDER BY pk LIMIT n`). Related rows are fetched per batch with `IN (...)`, one query per relation, so there are no joins and no Cartesian products. One-to-many relations are capped per parent with `ROW_NUMBER()`, the true count is reported in the text and in `truncated`. |
|
|
109
|
+
| Serialise | Deterministic templates. Nulls render as "not recorded"; if a templated field is null, the record falls back to explicit `Field: value.` text instead of producing a misleading sentence. No LLM is involved. |
|
|
110
|
+
| Embed | `"local"` = sentence-transformers (default `all-MiniLM-L6-v2`), `"hashing"` = dependency-free lexical hashing, or any object implementing `EmbeddingProvider`. |
|
|
111
|
+
| Store | `LocalVectorStore`: one SQLite file with float32 vectors, JSON metadata and checkpoints. No pickle. Exact cosine search, streamed in bounded chunks (memory does not grow with the index). |
|
|
112
|
+
| Re-index | Idempotent: vector ids are derived from the primary key, unchanged content (by hash) is not re-embedded, rows that disappeared are pruned when a run completes. Each batch commits atomically with its checkpoint; `index(resume=True)` continues an interrupted run. |
|
|
113
|
+
|
|
114
|
+
Search results carry `vector_id`, `score`, `text`, `source_table`, `source_pk`, `metadata`,
|
|
115
|
+
`references` (the related rows used, by primary key) and `truncated`. Metadata can be filtered
|
|
116
|
+
exactly: `rv.search(q, filters={"orders.status": "delayed"})`.
|
|
117
|
+
|
|
118
|
+
**A high similarity score is not evidence of causation or of a fact.** It means the text of
|
|
119
|
+
a record is close to the query in embedding space. Check the source rows.
|
|
120
|
+
|
|
121
|
+
## Safety defaults
|
|
122
|
+
|
|
123
|
+
* Source connections are read-only: SQLite opens with `mode=ro` (a missing file is an error,
|
|
124
|
+
never created); PostgreSQL sessions use `READ ONLY`, `REPEATABLE READ` transactions. Use a
|
|
125
|
+
read-only database role as well. If you pass your own `engine=`, these settings are yours to
|
|
126
|
+
configure.
|
|
127
|
+
* Only `SELECT` statements built with SQLAlchemy Core run, with bound parameters. There is no
|
|
128
|
+
free-form SQL input.
|
|
129
|
+
* Columns whose names look sensitive (email, phone, password, SSN, card number and so on) are
|
|
130
|
+
refused in `text_fields`/`metadata_fields` unless listed in `allow_sensitive`. Name heuristics
|
|
131
|
+
are incomplete: `notes` may hold anything, so review every field you map.
|
|
132
|
+
* Providers that send text off the machine must declare `sends_data_externally = True` and
|
|
133
|
+
are refused unless you pass `allow_external_embeddings=True`.
|
|
134
|
+
* `repr()` hides passwords in connection URLs.
|
|
135
|
+
* Optional [SQLGuard Ninja](https://pypi.org/project/sqlguard-ninja/) integration validates every extraction
|
|
136
|
+
query against a policy and blocks on denial:
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
from sqlguard_ninja import Guard, Policy
|
|
140
|
+
from relvector.integrations.sqlguard import SQLGuardValidator
|
|
141
|
+
|
|
142
|
+
rv = RelVector(url, sql_validator=SQLGuardValidator(Guard(Policy.from_file("policy.yaml")),
|
|
143
|
+
role="indexer"))
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
SQLGuard approval means the query is allowed for the role. It does not mean the values may
|
|
147
|
+
be embedded and stored; that decision belongs to the mapping.
|
|
148
|
+
|
|
149
|
+
## Known limitations
|
|
150
|
+
|
|
151
|
+
* This is a trusted-developer library. The index file contains embedded text and metadata in
|
|
152
|
+
plain form. Anyone who can read it can read that data. There is no row-level or tenant
|
|
153
|
+
isolation in the index.
|
|
154
|
+
* Relationships: one hop from the root table, single-column joins. No self-references,
|
|
155
|
+
multi-hop paths or composite foreign keys yet. Composite root primary keys are supported.
|
|
156
|
+
* Re-indexing is a full re-scan. There is no change-data-capture, and no triggers or timestamps
|
|
157
|
+
are used. Edits to related rows (child shipments, a parent customer) are picked up on the
|
|
158
|
+
next completed run. Rows changed during a run may be read at different moments, and the next
|
|
159
|
+
run corrects them. See
|
|
160
|
+
[how source changes reach documents](docs/relvector/architecture.md#how-source-changes-reach-semantic-documents).
|
|
161
|
+
* Only one writer per entity at a time. A new run, or a resume of the same run in another
|
|
162
|
+
process, takes over the checkpoint. The displaced writer stops with `RunSupersededError` at
|
|
163
|
+
its next batch and never prunes. This is a takeover, not a lock: it doesn't stop two writers
|
|
164
|
+
from embedding the same batch, and those duplicate writes are harmless upserts.
|
|
165
|
+
* Checkpoints keep primary-key types (int, str, date, datetime, time, Decimal, UUID, bytes), so
|
|
166
|
+
a resumed scan compares keys as the column does. Other key types cannot be checkpointed and
|
|
167
|
+
fail with a clear error.
|
|
168
|
+
* `LocalVectorStore` search is exact and streamed: memory is bounded by
|
|
169
|
+
`search_chunk_size` (default 1024 rows) and `top_k`, but every query scans all vectors that
|
|
170
|
+
pass the filters. Latency grows linearly with index size, and there is no approximate (ANN)
|
|
171
|
+
index. See [search performance](docs/relvector/architecture.md#search-performance).
|
|
172
|
+
* The hashing provider is lexical, not semantic.
|
|
173
|
+
* SQLite and PostgreSQL only. Other databases are not supported.
|
|
174
|
+
|
|
175
|
+
## Development
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
pip install -e ".[dev]"
|
|
179
|
+
pytest # model and PostgreSQL tests skip unless available (see CONTRIBUTING.md)
|
|
180
|
+
ruff check src/relvector tests/relvector examples/relvector
|
|
181
|
+
mypy
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Architecture, reuse decisions and roadmap: [docs/relvector/architecture.md](docs/relvector/architecture.md).
|
|
185
|
+
|
|
186
|
+
## License
|
|
187
|
+
|
|
188
|
+
Apache-2.0. See [LICENSE](LICENSE) and [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md). This
|
|
189
|
+
repository grew out of SQLGuard Ninja (same authors and licence), whose history it keeps.
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# RelVector
|
|
2
|
+
|
|
3
|
+
**Schema-aware semantic indexes over existing relational databases.**
|
|
4
|
+
|
|
5
|
+
RelVector makes selected relational data semantically searchable without migrating or
|
|
6
|
+
modifying the source database. It reads your schema, follows declared foreign keys, turns each
|
|
7
|
+
root row plus its related rows into deterministic, readable text, embeds it with a
|
|
8
|
+
pluggable provider and stores the vectors in a persistent local index. Every search result
|
|
9
|
+
points back to the exact source rows.
|
|
10
|
+
|
|
11
|
+
RelVector does **not** convert a database into a vector database. The database stays the
|
|
12
|
+
authoritative source and is only ever read.
|
|
13
|
+
|
|
14
|
+
> Status: `0.1.0`, alpha. Tested with SQLite and PostgreSQL 16. APIs may change before 1.0.
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
Python 3.11+:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install relvector # core: SQLAlchemy + NumPy
|
|
22
|
+
pip install "relvector[local]" # + sentence-transformers for local embeddings (pulls in PyTorch)
|
|
23
|
+
pip install "relvector[postgres]" # + psycopg 3; use postgresql+psycopg://user@host/db URLs
|
|
24
|
+
pip install "relvector[sqlguard]" # + optional SQLGuard Ninja query validation
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
For development, use `pip install -e ".[dev]"` from a checkout.
|
|
28
|
+
|
|
29
|
+
## Quick start
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
from relvector import RelVector
|
|
33
|
+
|
|
34
|
+
with RelVector("sqlite:///shop.db", embedding_provider="local",
|
|
35
|
+
index_path="shop.rvindex") as rv:
|
|
36
|
+
print(rv.inspect_schema().describe()) # tables, columns, PKs, foreign keys
|
|
37
|
+
|
|
38
|
+
rv.configure(
|
|
39
|
+
root_table="orders", # one semantic record per order
|
|
40
|
+
include_tables=["shipments"], # joined via the declared foreign key
|
|
41
|
+
text_fields=["orders.status", "shipments.delay_reason"], # embedded
|
|
42
|
+
metadata_fields=["orders.status"], # stored and filterable, not embedded
|
|
43
|
+
exclude_fields=["customers.email"],
|
|
44
|
+
templates={
|
|
45
|
+
"orders": "Order {id} is {status}.",
|
|
46
|
+
"shipments": "Its associated shipment has a {delay_reason}.",
|
|
47
|
+
},
|
|
48
|
+
)
|
|
49
|
+
stats = rv.index(batch_size=500)
|
|
50
|
+
print(stats) # rows, embedded, unchanged, deleted, timings, rows/s
|
|
51
|
+
|
|
52
|
+
for hit in rv.search("orders delayed because of transport problems", top_k=5):
|
|
53
|
+
print(hit.score, hit.source_table, hit.source_pk, hit.references)
|
|
54
|
+
print(hit.text)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The record for order 1002 reads:
|
|
58
|
+
`Order 1002 is delayed. Its associated shipment has a carrier capacity shortage.`
|
|
59
|
+
|
|
60
|
+
Runnable example: [examples/relvector/orders_shipments.py](examples/relvector/orders_shipments.py)
|
|
61
|
+
(`--provider hashing` runs without any model).
|
|
62
|
+
|
|
63
|
+
## How it works
|
|
64
|
+
|
|
65
|
+
| Stage | Behaviour |
|
|
66
|
+
|---|---|
|
|
67
|
+
| Inspect | SQLAlchemy inspector: tables, columns, primary keys, declared foreign keys. Catalog only, no rows. |
|
|
68
|
+
| Map | `EntityMapping`: root table, directly related tables (FK or explicit `Include(via=...)`), `text_fields`, `metadata_fields`, `exclude_fields`. Only listed columns are ever selected. |
|
|
69
|
+
| Extract | Keyset pagination on the primary key (`WHERE pk > :last ORDER BY pk LIMIT n`). Related rows are fetched per batch with `IN (...)`, one query per relation, so there are no joins and no Cartesian products. One-to-many relations are capped per parent with `ROW_NUMBER()`, the true count is reported in the text and in `truncated`. |
|
|
70
|
+
| Serialise | Deterministic templates. Nulls render as "not recorded"; if a templated field is null, the record falls back to explicit `Field: value.` text instead of producing a misleading sentence. No LLM is involved. |
|
|
71
|
+
| Embed | `"local"` = sentence-transformers (default `all-MiniLM-L6-v2`), `"hashing"` = dependency-free lexical hashing, or any object implementing `EmbeddingProvider`. |
|
|
72
|
+
| Store | `LocalVectorStore`: one SQLite file with float32 vectors, JSON metadata and checkpoints. No pickle. Exact cosine search, streamed in bounded chunks (memory does not grow with the index). |
|
|
73
|
+
| Re-index | Idempotent: vector ids are derived from the primary key, unchanged content (by hash) is not re-embedded, rows that disappeared are pruned when a run completes. Each batch commits atomically with its checkpoint; `index(resume=True)` continues an interrupted run. |
|
|
74
|
+
|
|
75
|
+
Search results carry `vector_id`, `score`, `text`, `source_table`, `source_pk`, `metadata`,
|
|
76
|
+
`references` (the related rows used, by primary key) and `truncated`. Metadata can be filtered
|
|
77
|
+
exactly: `rv.search(q, filters={"orders.status": "delayed"})`.
|
|
78
|
+
|
|
79
|
+
**A high similarity score is not evidence of causation or of a fact.** It means the text of
|
|
80
|
+
a record is close to the query in embedding space. Check the source rows.
|
|
81
|
+
|
|
82
|
+
## Safety defaults
|
|
83
|
+
|
|
84
|
+
* Source connections are read-only: SQLite opens with `mode=ro` (a missing file is an error,
|
|
85
|
+
never created); PostgreSQL sessions use `READ ONLY`, `REPEATABLE READ` transactions. Use a
|
|
86
|
+
read-only database role as well. If you pass your own `engine=`, these settings are yours to
|
|
87
|
+
configure.
|
|
88
|
+
* Only `SELECT` statements built with SQLAlchemy Core run, with bound parameters. There is no
|
|
89
|
+
free-form SQL input.
|
|
90
|
+
* Columns whose names look sensitive (email, phone, password, SSN, card number and so on) are
|
|
91
|
+
refused in `text_fields`/`metadata_fields` unless listed in `allow_sensitive`. Name heuristics
|
|
92
|
+
are incomplete: `notes` may hold anything, so review every field you map.
|
|
93
|
+
* Providers that send text off the machine must declare `sends_data_externally = True` and
|
|
94
|
+
are refused unless you pass `allow_external_embeddings=True`.
|
|
95
|
+
* `repr()` hides passwords in connection URLs.
|
|
96
|
+
* Optional [SQLGuard Ninja](https://pypi.org/project/sqlguard-ninja/) integration validates every extraction
|
|
97
|
+
query against a policy and blocks on denial:
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
from sqlguard_ninja import Guard, Policy
|
|
101
|
+
from relvector.integrations.sqlguard import SQLGuardValidator
|
|
102
|
+
|
|
103
|
+
rv = RelVector(url, sql_validator=SQLGuardValidator(Guard(Policy.from_file("policy.yaml")),
|
|
104
|
+
role="indexer"))
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
SQLGuard approval means the query is allowed for the role. It does not mean the values may
|
|
108
|
+
be embedded and stored; that decision belongs to the mapping.
|
|
109
|
+
|
|
110
|
+
## Known limitations
|
|
111
|
+
|
|
112
|
+
* This is a trusted-developer library. The index file contains embedded text and metadata in
|
|
113
|
+
plain form. Anyone who can read it can read that data. There is no row-level or tenant
|
|
114
|
+
isolation in the index.
|
|
115
|
+
* Relationships: one hop from the root table, single-column joins. No self-references,
|
|
116
|
+
multi-hop paths or composite foreign keys yet. Composite root primary keys are supported.
|
|
117
|
+
* Re-indexing is a full re-scan. There is no change-data-capture, and no triggers or timestamps
|
|
118
|
+
are used. Edits to related rows (child shipments, a parent customer) are picked up on the
|
|
119
|
+
next completed run. Rows changed during a run may be read at different moments, and the next
|
|
120
|
+
run corrects them. See
|
|
121
|
+
[how source changes reach documents](docs/relvector/architecture.md#how-source-changes-reach-semantic-documents).
|
|
122
|
+
* Only one writer per entity at a time. A new run, or a resume of the same run in another
|
|
123
|
+
process, takes over the checkpoint. The displaced writer stops with `RunSupersededError` at
|
|
124
|
+
its next batch and never prunes. This is a takeover, not a lock: it doesn't stop two writers
|
|
125
|
+
from embedding the same batch, and those duplicate writes are harmless upserts.
|
|
126
|
+
* Checkpoints keep primary-key types (int, str, date, datetime, time, Decimal, UUID, bytes), so
|
|
127
|
+
a resumed scan compares keys as the column does. Other key types cannot be checkpointed and
|
|
128
|
+
fail with a clear error.
|
|
129
|
+
* `LocalVectorStore` search is exact and streamed: memory is bounded by
|
|
130
|
+
`search_chunk_size` (default 1024 rows) and `top_k`, but every query scans all vectors that
|
|
131
|
+
pass the filters. Latency grows linearly with index size, and there is no approximate (ANN)
|
|
132
|
+
index. See [search performance](docs/relvector/architecture.md#search-performance).
|
|
133
|
+
* The hashing provider is lexical, not semantic.
|
|
134
|
+
* SQLite and PostgreSQL only. Other databases are not supported.
|
|
135
|
+
|
|
136
|
+
## Development
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
pip install -e ".[dev]"
|
|
140
|
+
pytest # model and PostgreSQL tests skip unless available (see CONTRIBUTING.md)
|
|
141
|
+
ruff check src/relvector tests/relvector examples/relvector
|
|
142
|
+
mypy
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Architecture, reuse decisions and roadmap: [docs/relvector/architecture.md](docs/relvector/architecture.md).
|
|
146
|
+
|
|
147
|
+
## License
|
|
148
|
+
|
|
149
|
+
Apache-2.0. See [LICENSE](LICENSE) and [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md). This
|
|
150
|
+
repository grew out of SQLGuard Ninja (same authors and licence), whose history it keeps.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
## RelVector (the `relvector` wheel)
|
|
4
|
+
|
|
5
|
+
RelVector is licensed under Apache-2.0. **It does not vendor or copy third-party source code.**
|
|
6
|
+
The one adapted piece is the list of sensitive-column name patterns in
|
|
7
|
+
`src/relvector/mapping.py`. It comes from SQLGuard Ninja (`sqlguard_ninja/privacy/suggest.py`),
|
|
8
|
+
which has the same authors and the same Apache-2.0 licence.
|
|
9
|
+
|
|
10
|
+
The packages below are ordinary dependencies, installed by the package manager under their
|
|
11
|
+
own licences. Licences were read from installed package metadata on 2026-10-25. Always check
|
|
12
|
+
the version you install.
|
|
13
|
+
|
|
14
|
+
### Runtime dependencies (core install)
|
|
15
|
+
|
|
16
|
+
| Package | Version tested | Licence | Use |
|
|
17
|
+
|---|---|---|---|
|
|
18
|
+
| [SQLAlchemy](https://www.sqlalchemy.org/) | 2.1.6 | MIT | Schema inspection, query construction, connections |
|
|
19
|
+
| [NumPy](https://numpy.org/) | 2.4.6 | BSD-3-Clause (bundled parts: 0BSD, MIT, Zlib, CC0-1.0) | Vector arithmetic |
|
|
20
|
+
|
|
21
|
+
### Optional extras
|
|
22
|
+
|
|
23
|
+
| Extra | Package | Version tested | Licence |
|
|
24
|
+
|---|---|---|---|
|
|
25
|
+
| `local` | sentence-transformers | 6.2.0 | Apache-2.0 |
|
|
26
|
+
| `local` (transitive) | torch / transformers | 2.14.1 (CPU) / 5.20.2 | BSD-3-Clause and others (see the package) / Apache-2.0 |
|
|
27
|
+
| `postgres` | psycopg (+ psycopg-binary) | 3.3.6 | LGPL-3.0-only |
|
|
28
|
+
| `sqlguard` | sqlguard-ninja | 0.7.0 | Apache-2.0 |
|
|
29
|
+
|
|
30
|
+
psycopg is LGPL-3.0. RelVector does not import it directly; SQLAlchemy loads it at runtime when
|
|
31
|
+
a `postgresql+psycopg://` URL is used. It is not modified or bundled.
|
|
32
|
+
|
|
33
|
+
Embedding models are not part of RelVector. The default local model,
|
|
34
|
+
`sentence-transformers/all-MiniLM-L6-v2`, is published under Apache-2.0. Models are downloaded
|
|
35
|
+
by sentence-transformers under their own licences; check the licence of any model you configure.
|
|
36
|
+
|
|
37
|
+
### Development and test tools (not distributed)
|
|
38
|
+
|
|
39
|
+
pytest (MIT), ruff (MIT), mypy (MIT), build (MIT), twine (Apache-2.0). PostgreSQL tests can
|
|
40
|
+
use `pgserver` (not a declared dependency; it bundles PostgreSQL binaries under the
|
|
41
|
+
PostgreSQL License) or a PostgreSQL 16 service container in CI.
|
|
42
|
+
|
|
43
|
+
## Origin of this repository
|
|
44
|
+
|
|
45
|
+
RelVector's repository began as a copy of SQLGuard Ninja (Apache-2.0, same authors). The
|
|
46
|
+
SQLGuard Ninja sources, benchmarks and their third-party notices have been removed from the
|
|
47
|
+
working tree. They remain in this repository's git history, and SQLGuard Ninja is developed
|
|
48
|
+
and published separately (`pip install sqlguard-ninja`). RelVector uses it only as an optional
|
|
49
|
+
dependency.
|
|
50
|
+
|
|
51
|
+
## GitHub Actions
|
|
52
|
+
|
|
53
|
+
`actions/checkout`, `actions/setup-python` and `actions/upload-artifact` (MIT, GitHub) are
|
|
54
|
+
referenced by commit SHA in the workflows.
|