@infino-ai/infino 0.1.0
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.
- package/LICENSE +202 -0
- package/README.md +348 -0
- package/infino/index.d.ts +146 -0
- package/infino/index.js +271 -0
- package/infino/native.d.ts +167 -0
- package/infino/native.js +319 -0
- package/package.json +102 -0
package/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.
|
package/README.md
ADDED
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
# infino
|
|
2
|
+
|
|
3
|
+
**SQL, full-text, and vector search over your data on object storage — one engine, no server to run.**
|
|
4
|
+
|
|
5
|
+
Infino keeps your data in Apache Parquet on object storage (local disk, Amazon
|
|
6
|
+
S3, or any S3-compatible store) and runs SQL, full-text (BM25), and vector
|
|
7
|
+
search over it from a single system. Each file is a valid Parquet file with BM25
|
|
8
|
+
and vector indexes embedded directly inside it; a table composes many such files
|
|
9
|
+
with snapshot-isolated reads, append-only writes, and atomic commits. It runs in
|
|
10
|
+
your process — there is no daemon, no cluster, and no managed service to operate.
|
|
11
|
+
|
|
12
|
+
Use it for **RAG**, **agent memory**, **hybrid search**, and **semantic search**:
|
|
13
|
+
it's an embedded **vector database**, **full-text (BM25)** search engine, and
|
|
14
|
+
**SQL** query engine in one library — no separate vector database or search
|
|
15
|
+
server to run.
|
|
16
|
+
|
|
17
|
+
Synchronous, Arrow at the boundary: pass arrays of objects (or apache-arrow
|
|
18
|
+
`Table`s) in, get plain records out; pass `{ arrow: true }` to a search or query
|
|
19
|
+
for an apache-arrow `Table` instead.
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
npm install @infino-ai/infino
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
A prebuilt native binary is selected automatically at install time — no Rust
|
|
28
|
+
toolchain required. Supported platforms:
|
|
29
|
+
|
|
30
|
+
| Platform | Architectures |
|
|
31
|
+
| --------------------- | ------------- |
|
|
32
|
+
| macOS | x64, arm64 |
|
|
33
|
+
| Linux (glibc) | x64, arm64 |
|
|
34
|
+
| Linux (musl / Alpine) | x64, arm64 |
|
|
35
|
+
|
|
36
|
+
`apache-arrow` is installed as a dependency and used at the boundary (passing in
|
|
37
|
+
`Table`s, or `{ arrow: true }` results). Requires Node.js >= 18.
|
|
38
|
+
|
|
39
|
+
## Quickstart
|
|
40
|
+
|
|
41
|
+
```javascript
|
|
42
|
+
import { connect, IndexSpec } from "@infino-ai/infino";
|
|
43
|
+
|
|
44
|
+
// Connect to a catalog. Use a local path or an S3 URI for durable storage;
|
|
45
|
+
// "memory://" is ephemeral and handy for tests.
|
|
46
|
+
const db = connect("./data");
|
|
47
|
+
|
|
48
|
+
// Tiny stand-in for your embedding model so this runs as-is — a 16-dim
|
|
49
|
+
// one-hot by topic. Real embeddings are dense and higher-dimensional.
|
|
50
|
+
const embed = (topic) => { const v = Array(16).fill(0.0); v[topic] = 1.0; return v; };
|
|
51
|
+
|
|
52
|
+
// Declare a schema and which columns to index. An `_id` column is added
|
|
53
|
+
// automatically — you don't define it.
|
|
54
|
+
const docs = db.createTable(
|
|
55
|
+
"docs",
|
|
56
|
+
{ source: "large_utf8", body: "large_utf8", embedding: { vector: 16 } },
|
|
57
|
+
new IndexSpec().fts("body").vector("embedding", 16, 1, "cosine"),
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
// Append rows. One append is one atomic commit.
|
|
61
|
+
docs.append([
|
|
62
|
+
{ source: "help-center", body: "To cancel a subscription, open Settings then Billing.", embedding: embed(0) },
|
|
63
|
+
{ source: "help-center", body: "Refunds return to the original payment method.", embedding: embed(0) },
|
|
64
|
+
{ source: "blog", body: "Enable dark mode under Settings then Appearance.", embedding: embed(1) },
|
|
65
|
+
]);
|
|
66
|
+
|
|
67
|
+
// Three ways to retrieve context to ground an agent's next answer:
|
|
68
|
+
const keyword = docs.bm25Search("body", "cancel subscription", 5); // BM25
|
|
69
|
+
const semantic = docs.vectorSearch("embedding", embed(0), 5); // vector kNN
|
|
70
|
+
const billing = db.querySql("SELECT body FROM docs WHERE source = 'help-center'"); // SQL filter
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
CommonJS works too — `const { connect, IndexSpec } = require("@infino-ai/infino");`.
|
|
74
|
+
|
|
75
|
+
## Examples
|
|
76
|
+
|
|
77
|
+
Runnable, end-to-end examples in [`examples/`](examples) (each its own folder
|
|
78
|
+
with a README; build the addon first, then `npm install && node index.mjs`):
|
|
79
|
+
|
|
80
|
+
- [`agent-memory/`](examples/agent-memory) — infino as an AI agent's long-term
|
|
81
|
+
memory: load a real multi-session conversation, then recall it with hybrid
|
|
82
|
+
search, query it with SQL (`GROUP BY`, filters), and forget parts of it.
|
|
83
|
+
- [`hybrid-search-api/`](examples/hybrid-search-api) — an embedded HTTP search
|
|
84
|
+
service over a real product catalog, ranked by native `hybrid_search` — with
|
|
85
|
+
no separate search server to run.
|
|
86
|
+
|
|
87
|
+
## Core concepts
|
|
88
|
+
|
|
89
|
+
- **Connection** — a handle to a catalog (a set of tables under one URI). Open
|
|
90
|
+
it with `connect(uri)`.
|
|
91
|
+
- **Table** — an append-only, snapshot-isolated collection of rows. Each table
|
|
92
|
+
carries an auto-generated `_id` column.
|
|
93
|
+
- **IndexSpec** — declares which columns are full-text (BM25) and which are
|
|
94
|
+
vector indexed. Columns without an index are still stored, filterable in SQL,
|
|
95
|
+
and returnable via projection.
|
|
96
|
+
- **Commits** — every `append`, `update`, and `delete` is a single atomic
|
|
97
|
+
commit. Readers see a consistent snapshot and are never torn by a concurrent
|
|
98
|
+
write.
|
|
99
|
+
- **Arrow at the boundary** — searches return plain records (or an apache-arrow
|
|
100
|
+
`Table` with `{ arrow: true }`); `append` and `update` accept an array of
|
|
101
|
+
objects or an apache-arrow `Table` / `RecordBatch`.
|
|
102
|
+
|
|
103
|
+
## Full-text search
|
|
104
|
+
|
|
105
|
+
```javascript
|
|
106
|
+
const docs = db.createTable("docs", { title: "large_utf8" }, new IndexSpec().fts("title"));
|
|
107
|
+
docs.append([{ title: "the quick brown fox" }, { title: "a lazy dog" }]);
|
|
108
|
+
|
|
109
|
+
// Ranked BM25 — higher score is a better match.
|
|
110
|
+
docs.bm25Search("title", "quick fox", 10); // OR by default
|
|
111
|
+
docs.bm25Search("title", "quick fox", 10, { mode: "and" }); // require all terms
|
|
112
|
+
|
|
113
|
+
// Unranked matching (score is 0): every row containing the term(s),
|
|
114
|
+
// or an exact whole-value match.
|
|
115
|
+
docs.tokenMatch("title", "fox");
|
|
116
|
+
docs.exactMatch("title", "the quick brown fox");
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Vector search
|
|
120
|
+
|
|
121
|
+
Vector columns are `FixedSizeList<Float32, dim>` with `dim` in `[16, 4096]`. The
|
|
122
|
+
distance metric is fixed when you declare the index (`"cosine"`, `"l2sq"`, or
|
|
123
|
+
`"negdot"`); for vector results a smaller score is nearer. The query vector is a
|
|
124
|
+
`number[]` or `Float32Array`.
|
|
125
|
+
|
|
126
|
+
```javascript
|
|
127
|
+
const spec = new IndexSpec().vector("emb", 384, 256, "cosine"); // (column, dim, nCent, metric)
|
|
128
|
+
const vecs = db.createTable("vecs", { emb: { vector: 384 } }, spec);
|
|
129
|
+
|
|
130
|
+
vecs.vectorSearch("emb", queryVector, 10); // top-10 nearest
|
|
131
|
+
vecs.vectorSearch("emb", queryVector, 10, { nprobe: 32 }); // probe more partitions (recall)
|
|
132
|
+
vecs.vectorSearch("emb", queryVector, 10, { rerankMult: 4 }); // wider exact-rerank pool (recall)
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
**Filtered vector search.** Restrict the kNN to rows matching a text predicate —
|
|
136
|
+
a pushdown *pre-filter*, so you get the nearest *matching* rows (not a
|
|
137
|
+
post-filter over the global top-k). The filter `column` must be FTS-indexed.
|
|
138
|
+
|
|
139
|
+
```javascript
|
|
140
|
+
vecs.vectorSearch("emb", queryVector, 10, {
|
|
141
|
+
filter: { column: "title", query: "billing", mode: "or" },
|
|
142
|
+
});
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Hybrid search
|
|
146
|
+
|
|
147
|
+
Combine BM25 and vector search in **one query** with the `hybrid_search` table
|
|
148
|
+
function — a single pass over both indexes, fused inside the engine (no separate
|
|
149
|
+
reranker service, no two round-trips). Keyword-only search misses paraphrases;
|
|
150
|
+
vector-only search misses exact terms — hybrid gets both. Results come back
|
|
151
|
+
best-first with a fused `score`.
|
|
152
|
+
|
|
153
|
+
```javascript
|
|
154
|
+
const spec = new IndexSpec().fts("body").vector("emb", 384, 256, "cosine");
|
|
155
|
+
const docs = db.createTable("docs", { body: "large_utf8", emb: { vector: 384 } }, spec);
|
|
156
|
+
docs.append([{ body: "To cancel a subscription, open Settings then Billing.", emb: embed(/* … */) }]);
|
|
157
|
+
|
|
158
|
+
// hybrid_search(table, text_col, query_text, vec_col, query_vec, k)
|
|
159
|
+
const qvec = embed("how do I stop my plan?").join(",");
|
|
160
|
+
db.querySql(
|
|
161
|
+
`SELECT _id, score FROM hybrid_search('docs', 'body', 'cancel subscription', 'emb', '${qvec}', 10)`,
|
|
162
|
+
);
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
For a complete, runnable hybrid search service see the
|
|
166
|
+
[`hybrid-search-api` example](examples/hybrid-search-api).
|
|
167
|
+
|
|
168
|
+
## SQL
|
|
169
|
+
|
|
170
|
+
Run SQL across the catalog's tables for analytics and filtering; the search
|
|
171
|
+
functions are also available as SQL table functions. Results come back as plain
|
|
172
|
+
records (or an apache-arrow `Table` with `{ arrow: true }`).
|
|
173
|
+
|
|
174
|
+
```javascript
|
|
175
|
+
db.querySql("SELECT COUNT(*) AS n FROM docs");
|
|
176
|
+
db.querySql("SELECT title FROM docs WHERE title = 'a lazy dog'");
|
|
177
|
+
|
|
178
|
+
// The search methods are also SQL table functions — bm25_search, vector_search,
|
|
179
|
+
// and hybrid_search (see "Hybrid search" above) — so you can filter, join, and
|
|
180
|
+
// aggregate over search results.
|
|
181
|
+
db.querySql("SELECT _id, score FROM bm25_search('docs', 'title', 'fox', 10)");
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Projections
|
|
185
|
+
|
|
186
|
+
By default a search returns just `_id` and `score` — no row data is decoded.
|
|
187
|
+
Name the columns you want to materialize:
|
|
188
|
+
|
|
189
|
+
```javascript
|
|
190
|
+
docs.bm25Search("title", "fox", 10); // _id + score only
|
|
191
|
+
docs.bm25Search("title", "fox", 10, { projection: ["_id", "title", "score"] });
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Updates and deletes
|
|
195
|
+
|
|
196
|
+
Mutations require durable storage (a local path or object store, not
|
|
197
|
+
`memory://`). The predicate is a SQL boolean expression — the same thing you'd
|
|
198
|
+
write after `WHERE` — evaluated against the table's columns.
|
|
199
|
+
|
|
200
|
+
```javascript
|
|
201
|
+
docs.append([{ title: "draft post" }, { title: "spam" }]);
|
|
202
|
+
|
|
203
|
+
// Delete every row matching the predicate.
|
|
204
|
+
docs.delete("title = 'spam'");
|
|
205
|
+
|
|
206
|
+
// Replace matched rows 1:1 with new rows (same input shapes as append).
|
|
207
|
+
const stats = docs.update("title = 'draft post'", [{ title: "published post" }]);
|
|
208
|
+
console.log(stats.matched, stats.nTombstoned, stats.nNotFound);
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
`update` is a one-to-one replacement: the number of matched rows must equal the
|
|
212
|
+
number you supply, otherwise it throws. Both methods return `{ matched,
|
|
213
|
+
nTombstoned, nNotFound }`.
|
|
214
|
+
|
|
215
|
+
## Optimize
|
|
216
|
+
|
|
217
|
+
Many small appends produce many small files. `optimize` compacts them —
|
|
218
|
+
merging small or underfilled files into larger ones — which keeps reads efficient.
|
|
219
|
+
|
|
220
|
+
```javascript
|
|
221
|
+
docs.optimize(); // engine defaults
|
|
222
|
+
docs.optimize({ targetSuperfileSizeMb: 256, minFillPercent: 50 });
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## Storage backends
|
|
226
|
+
|
|
227
|
+
`connect` selects the backend from the URI:
|
|
228
|
+
|
|
229
|
+
| URI | Backend |
|
|
230
|
+
| --------------------- | ---------------------------------------- |
|
|
231
|
+
| `./data`, `/abs/path` | Local filesystem |
|
|
232
|
+
| `s3://bucket/prefix` | Amazon S3 / S3-compatible object storage |
|
|
233
|
+
| `memory://` | In-process, ephemeral (testing) |
|
|
234
|
+
|
|
235
|
+
For S3-compatible stores that need an explicit endpoint and static credentials,
|
|
236
|
+
pass them in `options` (omit to use ambient AWS credentials):
|
|
237
|
+
|
|
238
|
+
```javascript
|
|
239
|
+
const db = connect("s3://bucket/prefix", {
|
|
240
|
+
endpoint: "https://s3.example.com",
|
|
241
|
+
region: "us-east-1",
|
|
242
|
+
accessKey: "…",
|
|
243
|
+
secretKey: "…",
|
|
244
|
+
});
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Local disk cache
|
|
248
|
+
|
|
249
|
+
For object-storage-backed catalogs, a local disk cache keeps hot data on fast
|
|
250
|
+
local storage. `coldFetchMode` controls how cache misses are served:
|
|
251
|
+
`"hybrid_with_prefetch"`, `"range_only"`, or
|
|
252
|
+
`"lazy_foreground_with_background_fill"`.
|
|
253
|
+
|
|
254
|
+
```javascript
|
|
255
|
+
const db = connect("s3://bucket/prefix", {
|
|
256
|
+
cacheDir: "/mnt/nvme/infino-cache",
|
|
257
|
+
cacheBudgetBytes: 64 * 1024 ** 3,
|
|
258
|
+
coldFetchMode: "lazy_foreground_with_background_fill",
|
|
259
|
+
});
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## Schema and type requirements
|
|
263
|
+
|
|
264
|
+
- Full-text columns must be Arrow `LargeUtf8` (`"large_utf8"` in a descriptor).
|
|
265
|
+
- Vector columns must be `FixedSizeList<Float32, dim>` (`{ vector: dim }`) with
|
|
266
|
+
`dim` in `[16, 4096]`.
|
|
267
|
+
- The `_id` column is generated by the engine; do not declare it. It comes back
|
|
268
|
+
as a JavaScript `bigint`.
|
|
269
|
+
- `createTable` accepts an apache-arrow `Schema` or a plain `{ column: type }`
|
|
270
|
+
descriptor; `append` / `update` accept an array of objects or an apache-arrow
|
|
271
|
+
`Table` / `RecordBatch`, coerced against the table's declared schema.
|
|
272
|
+
|
|
273
|
+
## API reference
|
|
274
|
+
|
|
275
|
+
- `connect(uri, options?)` — backend from the URI scheme. `options`:
|
|
276
|
+
S3-compatible credentials (`endpoint`, `region`, `accessKey`, `secretKey` —
|
|
277
|
+
`endpoint` requires the other three) and, for remote-backed tables, a local
|
|
278
|
+
disk cache (`cacheDir`, `cacheBudgetBytes`, `coldFetchMode`).
|
|
279
|
+
- `Connection`
|
|
280
|
+
- `createTable(name, schema, IndexSpec)` / `openTable(name)` /
|
|
281
|
+
`dropTable(name, purge?)` (`purge = true` also deletes the data) /
|
|
282
|
+
`listTables()` / `querySql(sql, { arrow? })`.
|
|
283
|
+
- `Table`
|
|
284
|
+
- `append(data)` — one `append` is one commit.
|
|
285
|
+
- `bm25Search(col, q, k, { mode?, projection?, arrow? })` — ranked BM25.
|
|
286
|
+
- `vectorSearch(col, query, k, { nprobe?, rerankMult?, filter?, projection?, arrow? })`
|
|
287
|
+
— ranked kNN; `filter` (`{ column, query, mode? }`, `column` FTS-indexed) is
|
|
288
|
+
a pushdown pre-filter.
|
|
289
|
+
- `tokenMatch(col, q, { mode?, projection?, arrow? })` /
|
|
290
|
+
`exactMatch(col, value, { projection?, arrow? })` — unranked (`score` is `0`).
|
|
291
|
+
- `update(predicate, data)` / `delete(predicate)` — mutate rows matching a SQL
|
|
292
|
+
predicate; return `{ matched, nTombstoned, nNotFound }`; require durable
|
|
293
|
+
storage.
|
|
294
|
+
- `optimize({ maxMemoryMb?, minFillPercent?, targetSuperfileSizeMb? })`.
|
|
295
|
+
- `schema()` — the table's apache-arrow `Schema`.
|
|
296
|
+
- `IndexSpec().fts(col).vector(col, dim, nCent, metric)`.
|
|
297
|
+
- `BUILDER_ID` (named export) — the engine's build identifier string.
|
|
298
|
+
|
|
299
|
+
Search results default to `_id` + `score`; name columns in `projection` to
|
|
300
|
+
materialize row data.
|
|
301
|
+
|
|
302
|
+
## Building from source
|
|
303
|
+
|
|
304
|
+
The binding is built with [napi-rs](https://napi.rs/). Building requires a Rust
|
|
305
|
+
toolchain and access to crates.io.
|
|
306
|
+
|
|
307
|
+
```sh
|
|
308
|
+
cd infino-node
|
|
309
|
+
npm install && npm run build && npm test
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
## Notes
|
|
313
|
+
|
|
314
|
+
- The API is **synchronous**. In a long-running server, run calls in a
|
|
315
|
+
`worker_thread` so a query doesn't block the event loop.
|
|
316
|
+
|
|
317
|
+
## FAQ
|
|
318
|
+
|
|
319
|
+
**Is infino a vector database?** It does vector search, but it's more than that —
|
|
320
|
+
an embedded engine that runs vector search *and* full-text (BM25) *and* SQL over
|
|
321
|
+
one copy of your data. Reach for it wherever you'd use a vector database, plus the
|
|
322
|
+
cases a vector store alone can't cover: keyword search, filtering, joins, and
|
|
323
|
+
aggregates.
|
|
324
|
+
|
|
325
|
+
**Does it need a server?** No. It runs in your Node.js process — no daemon, no
|
|
326
|
+
cluster, no managed service. Your data is Parquet on local disk or S3.
|
|
327
|
+
|
|
328
|
+
**Can it do hybrid (keyword + vector) search?** Yes, natively — BM25 and vector
|
|
329
|
+
fused in a single pass via `hybrid_search` (see [Hybrid search](#hybrid-search)),
|
|
330
|
+
not a client-side rerank.
|
|
331
|
+
|
|
332
|
+
**Where is my data stored?** As Apache Parquet files on local disk or any
|
|
333
|
+
S3-compatible object store; each file embeds its own BM25 and vector indexes.
|
|
334
|
+
|
|
335
|
+
**Does it work with TypeScript?** Yes — the package ships type definitions and the
|
|
336
|
+
API is identical from JavaScript and TypeScript. Both ESM `import` and CommonJS
|
|
337
|
+
`require` work.
|
|
338
|
+
|
|
339
|
+
**Do I need a Rust toolchain to install it?** No — a prebuilt native binary is
|
|
340
|
+
selected automatically at install (macOS and Linux, x64 and arm64).
|
|
341
|
+
|
|
342
|
+
**Is it a good fit for RAG or agent memory?** Yes, that's a primary use case:
|
|
343
|
+
store documents or conversation history once, retrieve with hybrid search, and
|
|
344
|
+
filter/aggregate with SQL. See the runnable [examples](examples).
|
|
345
|
+
|
|
346
|
+
## License
|
|
347
|
+
|
|
348
|
+
Apache-2.0.
|