vectlite 0.1.4 → 0.1.8

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/README.md CHANGED
@@ -126,9 +126,11 @@ try {
126
126
  ### Text Helpers
127
127
 
128
128
  ```js
129
- // Handles embedding + sparse term generation for you
130
- vectlite.upsertText(db, 'doc1', 'Auth setup guide', embedFn, { source: 'docs' })
131
- const results = vectlite.searchText(db, 'how to authenticate', embedFn, { k: 5 })
129
+ async function run() {
130
+ // embedFn can be sync or async
131
+ await vectlite.upsertText(db, 'doc1', 'Auth setup guide', embedFn, { source: 'docs' })
132
+ const results = await vectlite.searchText(db, 'how to authenticate', embedFn, { k: 5 })
133
+ }
132
134
  ```
133
135
 
134
136
  ### Snapshots & Backup
@@ -191,6 +193,7 @@ console.log(outcome.results[0].explain) // Detailed scoring breakdown
191
193
 
192
194
  ## Links
193
195
 
196
+ - [Official Documentation](https://vectlite.mcsedition.org/)
194
197
  - [GitHub Repository](https://github.com/mcsedition-hub/vectlite)
195
198
  - [Issue Tracker](https://github.com/mcsedition-hub/vectlite/issues)
196
199
  - [PyPI Package](https://pypi.org/project/vectlite/)
package/index.d.ts CHANGED
@@ -10,6 +10,9 @@ export type Metadata = { [key: string]: MetadataValue }
10
10
  export type SparseVector = { [term: string]: number }
11
11
  export type NamedVectors = { [name: string]: number[] }
12
12
  export type Filter = { [key: string]: unknown }
13
+ export type TextEmbedding = ArrayLike<number>
14
+ export type TextEmbeddingResult = TextEmbedding | Promise<TextEmbedding>
15
+ export type TextEmbedder = (text: string) => TextEmbeddingResult
13
16
 
14
17
  export interface Record {
15
18
  namespace: string
@@ -164,19 +167,39 @@ export function upsertText(
164
167
  db: Database,
165
168
  id: string,
166
169
  text: string,
167
- embed: (text: string) => ArrayLike<number>,
170
+ embed: (text: string) => TextEmbedding,
168
171
  metadata?: Metadata | null,
169
172
  options?: WriteOptions,
170
173
  ): void
174
+ export function upsertText(
175
+ db: Database,
176
+ id: string,
177
+ text: string,
178
+ embed: (text: string) => Promise<TextEmbedding>,
179
+ metadata?: Metadata | null,
180
+ options?: WriteOptions,
181
+ ): Promise<void>
171
182
  export function searchText(
172
183
  db: Database,
173
184
  text: string,
174
- embed: (text: string) => ArrayLike<number>,
185
+ embed: (text: string) => TextEmbedding,
175
186
  options?: SearchOptions,
176
187
  ): SearchResult[]
188
+ export function searchText(
189
+ db: Database,
190
+ text: string,
191
+ embed: (text: string) => Promise<TextEmbedding>,
192
+ options?: SearchOptions,
193
+ ): Promise<SearchResult[]>
177
194
  export function searchTextWithStats(
178
195
  db: Database,
179
196
  text: string,
180
- embed: (text: string) => ArrayLike<number>,
197
+ embed: (text: string) => TextEmbedding,
181
198
  options?: SearchOptions,
182
199
  ): SearchResponse
200
+ export function searchTextWithStats(
201
+ db: Database,
202
+ text: string,
203
+ embed: (text: string) => Promise<TextEmbedding>,
204
+ options?: SearchOptions,
205
+ ): Promise<SearchResponse>
package/index.js CHANGED
@@ -85,6 +85,15 @@ function wrapError(fn) {
85
85
  }
86
86
  }
87
87
 
88
+ function wrapAsync(value) {
89
+ return Promise.resolve(value).catch((error) => {
90
+ if (error instanceof VectLiteError) {
91
+ throw error
92
+ }
93
+ throw new VectLiteError(error?.message ?? String(error), error)
94
+ })
95
+ }
96
+
88
97
  function encode(value) {
89
98
  return value == null ? null : JSON.stringify(value)
90
99
  }
@@ -97,6 +106,18 @@ function asArray(values) {
97
106
  return Array.from(values)
98
107
  }
99
108
 
109
+ function isPromiseLike(value) {
110
+ return value != null && typeof value.then === 'function'
111
+ }
112
+
113
+ function embedText(text, embed) {
114
+ const embedded = wrapError(() => embed(text))
115
+ if (isPromiseLike(embedded)) {
116
+ return wrapAsync(embedded).then((vector) => asArray(vector))
117
+ }
118
+ return asArray(embedded)
119
+ }
120
+
100
121
  function normalizeWriteOptions(options = {}) {
101
122
  return {
102
123
  namespace: options.namespace ?? null,
@@ -318,15 +339,30 @@ function upsertText(db, id, text, embed, metadata = null, options = {}) {
318
339
  if (payload.text === undefined) {
319
340
  payload.text = text
320
341
  }
321
- return db.upsert(id, asArray(embed(text)), payload, { ...options, sparse: sparseTerms(text) })
342
+ const vector = embedText(text, embed)
343
+ const writeOptions = { ...options, sparse: sparseTerms(text) }
344
+ if (isPromiseLike(vector)) {
345
+ return wrapAsync(vector.then((resolved) => db.upsert(id, resolved, payload, writeOptions)))
346
+ }
347
+ return db.upsert(id, vector, payload, writeOptions)
322
348
  }
323
349
 
324
350
  function searchText(db, text, embed, options = {}) {
325
- return db.search(asArray(embed(text)), { ...options, sparse: sparseTerms(text) })
351
+ const vector = embedText(text, embed)
352
+ const searchOptions = { ...options, sparse: sparseTerms(text) }
353
+ if (isPromiseLike(vector)) {
354
+ return wrapAsync(vector.then((resolved) => db.search(resolved, searchOptions)))
355
+ }
356
+ return db.search(vector, searchOptions)
326
357
  }
327
358
 
328
359
  function searchTextWithStats(db, text, embed, options = {}) {
329
- return db.searchWithStats(asArray(embed(text)), { ...options, sparse: sparseTerms(text) })
360
+ const vector = embedText(text, embed)
361
+ const searchOptions = { ...options, sparse: sparseTerms(text) }
362
+ if (isPromiseLike(vector)) {
363
+ return wrapAsync(vector.then((resolved) => db.searchWithStats(resolved, searchOptions)))
364
+ }
365
+ return db.searchWithStats(vector, searchOptions)
330
366
  }
331
367
 
332
368
  module.exports = {
package/native/Cargo.toml CHANGED
@@ -1,12 +1,12 @@
1
1
  [package]
2
2
  name = "vectlite-node"
3
- version = "0.1.4"
3
+ version = "0.1.8"
4
4
  edition = "2024"
5
5
  license = "MIT"
6
6
  description = "Node.js bindings for vectlite."
7
- homepage = "https://github.com/mcsedition-hub/vectlite"
7
+ homepage = "https://vectlite.mcsedition.org/"
8
8
  repository = "https://github.com/mcsedition-hub/vectlite"
9
- documentation = "https://github.com/mcsedition-hub/vectlite/tree/main/bindings/node"
9
+ documentation = "https://vectlite.mcsedition.org/"
10
10
  build = "build.rs"
11
11
 
12
12
  [lib]
@@ -1,12 +1,12 @@
1
1
  [package]
2
2
  name = "vectlite-core"
3
- version = "0.1.4"
3
+ version = "0.1.8"
4
4
  edition = "2024"
5
5
  license = "MIT"
6
6
  description = "Core storage engine for vectlite."
7
- homepage = "https://github.com/mcsedition-hub/vectlite"
7
+ homepage = "https://vectlite.mcsedition.org/"
8
8
  repository = "https://github.com/mcsedition-hub/vectlite"
9
- documentation = "https://github.com/mcsedition-hub/vectlite"
9
+ documentation = "https://vectlite.mcsedition.org/"
10
10
 
11
11
  [lib]
12
12
  name = "vectlite"
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "vectlite",
3
- "version": "0.1.4",
3
+ "version": "0.1.8",
4
4
  "description": "Embedded vector store for local-first AI applications.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
- "homepage": "https://github.com/mcsedition-hub/vectlite/tree/main/bindings/node",
7
+ "homepage": "https://vectlite.mcsedition.org/",
8
8
  "repository": {
9
9
  "type": "git",
10
10
  "url": "git+https://github.com/mcsedition-hub/vectlite.git",