libsql-search 0.1.6 → 0.2.1
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/dist/index.cjs +425 -66
- package/dist/index.d.ts +46 -4
- package/dist/index.esm.js +422 -67
- package/docs/API.md +103 -0
- package/docs/PROVIDERS.md +66 -0
- package/package.json +1 -1
package/docs/PROVIDERS.md
CHANGED
|
@@ -18,15 +18,74 @@ interface EmbeddingOptions {
|
|
|
18
18
|
apiKey?: string;
|
|
19
19
|
dimensions?: number;
|
|
20
20
|
maxLength?: number;
|
|
21
|
+
intent?: "document" | "query";
|
|
22
|
+
timeoutMs?: number;
|
|
23
|
+
signal?: AbortSignal;
|
|
21
24
|
}
|
|
22
25
|
```
|
|
23
26
|
|
|
24
27
|
- `provider` defaults to `"local"`
|
|
25
28
|
- `dimensions` defaults to `768`
|
|
26
29
|
- `maxLength` defaults to `8000`
|
|
30
|
+
- `intent` can be `"document"` or `"query"`; indexing defaults to
|
|
31
|
+
`"document"` and search defaults to `"query"` unless explicitly set
|
|
32
|
+
- `timeoutMs` defaults to `30000`
|
|
27
33
|
- `apiKey` is optional in code, but required for hosted providers unless the
|
|
28
34
|
matching environment variable is available
|
|
29
35
|
|
|
36
|
+
## Provider Contract
|
|
37
|
+
|
|
38
|
+
Each provider exposes immutable metadata:
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
interface EmbeddingProviderMetadata {
|
|
42
|
+
name: "local" | "gemini" | "openai";
|
|
43
|
+
model: string;
|
|
44
|
+
dimensions: number;
|
|
45
|
+
batch: {
|
|
46
|
+
mode: "native" | "sequential";
|
|
47
|
+
maxSize?: number;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Use `getEmbeddingProviderMetadata(options)` or
|
|
53
|
+
`createEmbeddingProvider(options).metadata` to inspect the effective model,
|
|
54
|
+
dimensions, and batch behavior. Metadata inspection does not require hosted
|
|
55
|
+
provider credentials.
|
|
56
|
+
|
|
57
|
+
Batch modes:
|
|
58
|
+
|
|
59
|
+
- `"native"` means the upstream provider accepts the batch in one request
|
|
60
|
+
- `"sequential"` means the library accepts a batch and processes items one at a
|
|
61
|
+
time
|
|
62
|
+
- when `maxSize` is present, it is a hard maximum enforced before provider or
|
|
63
|
+
network work
|
|
64
|
+
|
|
65
|
+
`generateEmbeddings(texts, options)` returns vectors in the same order as the
|
|
66
|
+
input texts. Provider responses are validated before database writes:
|
|
67
|
+
|
|
68
|
+
- result count must match input count
|
|
69
|
+
- each vector must match the provider's effective dimensions
|
|
70
|
+
- every vector value must be a finite number
|
|
71
|
+
- indexed batch responses must contain unique contiguous indices and are
|
|
72
|
+
reordered before being returned
|
|
73
|
+
|
|
74
|
+
Empty batches return `[]` without loading a local model, creating hosted clients,
|
|
75
|
+
or making network calls.
|
|
76
|
+
|
|
77
|
+
Lower-level provider clients return an `EmbeddingBatchResult` with the validated
|
|
78
|
+
vectors plus provider, model, dimensions, and intent. The compatibility helpers
|
|
79
|
+
`generateEmbedding()` and `generateEmbeddings()` return only arrays.
|
|
80
|
+
|
|
81
|
+
Gemini and OpenAI clients are scoped to their current options. They are not
|
|
82
|
+
cached globally across different credentials or configurations. The local Xenova
|
|
83
|
+
model can be cached by model name.
|
|
84
|
+
|
|
85
|
+
Hosted provider failures are reported with bounded provider/status/request-id
|
|
86
|
+
context and without raw upstream bodies, credentials, Authorization headers, or
|
|
87
|
+
full URLs with query strings.
|
|
88
|
+
|
|
30
89
|
## Local
|
|
31
90
|
|
|
32
91
|
Provider value: `local`
|
|
@@ -45,6 +104,8 @@ Notes:
|
|
|
45
104
|
|
|
46
105
|
- the model emits 384 dimensions and `libsql-search` pads or truncates to your
|
|
47
106
|
requested size
|
|
107
|
+
- metadata reports the requested output dimensions
|
|
108
|
+
- batch metadata is `{ mode: "sequential" }`
|
|
48
109
|
- the first run downloads the model and can take longer on a fresh machine
|
|
49
110
|
- no API key is required
|
|
50
111
|
|
|
@@ -65,6 +126,8 @@ Behavior:
|
|
|
65
126
|
|
|
66
127
|
- if `apiKey` is omitted, the library reads `GEMINI_API_KEY`
|
|
67
128
|
- Gemini returns 768 dimensions natively
|
|
129
|
+
- metadata reports `text-embedding-004` and 768 dimensions
|
|
130
|
+
- batch metadata is `{ mode: "sequential" }`
|
|
68
131
|
- the current implementation does not expose model selection
|
|
69
132
|
|
|
70
133
|
## OpenAI
|
|
@@ -86,6 +149,9 @@ Behavior:
|
|
|
86
149
|
|
|
87
150
|
- if `apiKey` is omitted, the library reads `OPENAI_API_KEY`
|
|
88
151
|
- the request sends the `dimensions` value to the OpenAI embeddings API
|
|
152
|
+
- metadata reports `text-embedding-3-small` when `dimensions <= 1536` and
|
|
153
|
+
`text-embedding-3-large` when `dimensions > 1536`
|
|
154
|
+
- batch metadata is `{ mode: "native", maxSize: 2048 }`
|
|
89
155
|
- use the same dimension count in `createTable()`
|
|
90
156
|
|
|
91
157
|
## Dimension Guidelines
|