neuralex 0.1.1 → 0.2.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/README.md +37 -1
- package/dist/index.d.mts +8 -3
- package/dist/index.d.ts +8 -3
- package/dist/index.js +27 -5
- package/dist/index.mjs +27 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -54,6 +54,7 @@ console.log(`First 5 values: ${embedding.slice(0, 5)}`);
|
|
|
54
54
|
- ✅ Configurable semantic/term-based balance
|
|
55
55
|
- ✅ Batch embedding support (up to 100 inputs)
|
|
56
56
|
- ✅ Tree-shakeable ESM and CommonJS builds
|
|
57
|
+
- ✅ BYOE (Bring Your Own Embedding) mode support
|
|
57
58
|
|
|
58
59
|
## Usage
|
|
59
60
|
|
|
@@ -107,6 +108,30 @@ const response = await client.embed('Python programming', {
|
|
|
107
108
|
});
|
|
108
109
|
```
|
|
109
110
|
|
|
111
|
+
### BYOE (Bring Your Own Embedding) Mode
|
|
112
|
+
|
|
113
|
+
When the embed service is configured with `BYOE=true`, you can provide your own
|
|
114
|
+
pre-computed embeddings instead of generating them server-side:
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
import { NeuraLexClient, EmbeddingInputData } from 'neuralex';
|
|
118
|
+
|
|
119
|
+
const client = new NeuraLexClient({ apiKey: 'nlx_your_api_key' });
|
|
120
|
+
|
|
121
|
+
// Create inputs with optional pre-computed embeddings
|
|
122
|
+
const inputs: EmbeddingInputData[] = [
|
|
123
|
+
// Provide your own embedding (must match server dimensions, typically 1024)
|
|
124
|
+
{ text: 'hello world', embedding: new Array(1024).fill(0.1) },
|
|
125
|
+
// Or let the server compute the embedding
|
|
126
|
+
{ text: 'server-computed text' },
|
|
127
|
+
];
|
|
128
|
+
|
|
129
|
+
const response = await client.embed(inputs);
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
**Note:** BYOE mode must be enabled on the server (`BYOE=true`). If BYOE is disabled,
|
|
133
|
+
providing embeddings will result in an error.
|
|
134
|
+
|
|
110
135
|
### Error Handling
|
|
111
136
|
|
|
112
137
|
```typescript
|
|
@@ -175,7 +200,7 @@ Generate embeddings for text input(s).
|
|
|
175
200
|
|
|
176
201
|
**Parameters:**
|
|
177
202
|
|
|
178
|
-
- `inputs` (string | string[]): Text or array of texts to embed (max 100)
|
|
203
|
+
- `inputs` (string | EmbeddingInputData | string[] | EmbeddingInputData[]): Text or array of texts/EmbeddingInputData to embed (max 100)
|
|
179
204
|
- `options` (object, optional):
|
|
180
205
|
- `model` (string): Model name (default: "public")
|
|
181
206
|
- `language` (string): Language for lexeme extraction (default: "english")
|
|
@@ -185,6 +210,17 @@ Generate embeddings for text input(s).
|
|
|
185
210
|
|
|
186
211
|
### Types
|
|
187
212
|
|
|
213
|
+
#### `EmbeddingInputData`
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
interface EmbeddingInputData {
|
|
217
|
+
/** Text to embed (required) */
|
|
218
|
+
text: string;
|
|
219
|
+
/** Pre-computed embedding vector (optional, for BYOE mode) */
|
|
220
|
+
embedding?: number[];
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
188
224
|
#### `EmbeddingResponse`
|
|
189
225
|
|
|
190
226
|
```typescript
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
interface EmbeddingInputData {
|
|
2
|
+
text: string;
|
|
3
|
+
embedding?: number[];
|
|
4
|
+
}
|
|
1
5
|
interface EmbeddingRequest {
|
|
2
|
-
inputs:
|
|
6
|
+
inputs: EmbeddingInputData[];
|
|
3
7
|
model?: string;
|
|
4
8
|
language?: string;
|
|
5
9
|
semanticWeight?: number;
|
|
@@ -23,11 +27,12 @@ interface NeuraLexClientConfig {
|
|
|
23
27
|
timeout?: number;
|
|
24
28
|
}
|
|
25
29
|
|
|
30
|
+
type EmbedInput = string | EmbeddingInputData | string[] | EmbeddingInputData[];
|
|
26
31
|
declare class NeuraLexClient {
|
|
27
32
|
private client;
|
|
28
33
|
private apiKey;
|
|
29
34
|
constructor(config: NeuraLexClientConfig);
|
|
30
|
-
embed(inputs:
|
|
35
|
+
embed(inputs: EmbedInput, options?: {
|
|
31
36
|
model?: string;
|
|
32
37
|
language?: string;
|
|
33
38
|
semanticWeight?: number;
|
|
@@ -49,4 +54,4 @@ declare class APIError extends NeuraLexError {
|
|
|
49
54
|
constructor(message: string, statusCode: number, responseData?: any);
|
|
50
55
|
}
|
|
51
56
|
|
|
52
|
-
export { APIError, AuthenticationError, type EmbeddingData, type EmbeddingRequest, type EmbeddingResponse, NeuraLexClient, type NeuraLexClientConfig, NeuraLexError, RateLimitError, type Usage };
|
|
57
|
+
export { APIError, AuthenticationError, type EmbeddingData, type EmbeddingInputData, type EmbeddingRequest, type EmbeddingResponse, NeuraLexClient, type NeuraLexClientConfig, NeuraLexError, RateLimitError, type Usage };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
interface EmbeddingInputData {
|
|
2
|
+
text: string;
|
|
3
|
+
embedding?: number[];
|
|
4
|
+
}
|
|
1
5
|
interface EmbeddingRequest {
|
|
2
|
-
inputs:
|
|
6
|
+
inputs: EmbeddingInputData[];
|
|
3
7
|
model?: string;
|
|
4
8
|
language?: string;
|
|
5
9
|
semanticWeight?: number;
|
|
@@ -23,11 +27,12 @@ interface NeuraLexClientConfig {
|
|
|
23
27
|
timeout?: number;
|
|
24
28
|
}
|
|
25
29
|
|
|
30
|
+
type EmbedInput = string | EmbeddingInputData | string[] | EmbeddingInputData[];
|
|
26
31
|
declare class NeuraLexClient {
|
|
27
32
|
private client;
|
|
28
33
|
private apiKey;
|
|
29
34
|
constructor(config: NeuraLexClientConfig);
|
|
30
|
-
embed(inputs:
|
|
35
|
+
embed(inputs: EmbedInput, options?: {
|
|
31
36
|
model?: string;
|
|
32
37
|
language?: string;
|
|
33
38
|
semanticWeight?: number;
|
|
@@ -49,4 +54,4 @@ declare class APIError extends NeuraLexError {
|
|
|
49
54
|
constructor(message: string, statusCode: number, responseData?: any);
|
|
50
55
|
}
|
|
51
56
|
|
|
52
|
-
export { APIError, AuthenticationError, type EmbeddingData, type EmbeddingRequest, type EmbeddingResponse, NeuraLexClient, type NeuraLexClientConfig, NeuraLexError, RateLimitError, type Usage };
|
|
57
|
+
export { APIError, AuthenticationError, type EmbeddingData, type EmbeddingInputData, type EmbeddingRequest, type EmbeddingResponse, NeuraLexClient, type NeuraLexClientConfig, NeuraLexError, RateLimitError, type Usage };
|
package/dist/index.js
CHANGED
|
@@ -74,6 +74,20 @@ var APIError = class _APIError extends NeuraLexError {
|
|
|
74
74
|
};
|
|
75
75
|
|
|
76
76
|
// src/client.ts
|
|
77
|
+
function normalizeInputs(inputs) {
|
|
78
|
+
if (typeof inputs === "string") {
|
|
79
|
+
return [{ text: inputs }];
|
|
80
|
+
}
|
|
81
|
+
if (!Array.isArray(inputs)) {
|
|
82
|
+
return [inputs];
|
|
83
|
+
}
|
|
84
|
+
return inputs.map((item) => {
|
|
85
|
+
if (typeof item === "string") {
|
|
86
|
+
return { text: item };
|
|
87
|
+
}
|
|
88
|
+
return item;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
77
91
|
var NeuraLexClient = class {
|
|
78
92
|
/**
|
|
79
93
|
* Create a new NeuraLex client
|
|
@@ -104,7 +118,9 @@ var NeuraLexClient = class {
|
|
|
104
118
|
/**
|
|
105
119
|
* Generate embeddings for the provided input text(s)
|
|
106
120
|
*
|
|
107
|
-
* @param inputs - Text string or array of
|
|
121
|
+
* @param inputs - Text string, EmbeddingInputData, or array of either (max 100).
|
|
122
|
+
* For BYOE (Bring Your Own Embedding) mode, use EmbeddingInputData
|
|
123
|
+
* with the embedding field populated.
|
|
108
124
|
* @param options - Optional parameters
|
|
109
125
|
* @param options.model - Model name (default: "public")
|
|
110
126
|
* @param options.language - Language for lexeme extraction (default: "english")
|
|
@@ -129,18 +145,24 @@ var NeuraLexClient = class {
|
|
|
129
145
|
* semanticWeight: 0.8,
|
|
130
146
|
* model: 'public'
|
|
131
147
|
* });
|
|
148
|
+
*
|
|
149
|
+
* // BYOE mode with pre-computed embeddings
|
|
150
|
+
* const response = await client.embed([
|
|
151
|
+
* { text: 'hello world', embedding: new Array(1024).fill(0.1) },
|
|
152
|
+
* { text: 'server-computed text' }
|
|
153
|
+
* ]);
|
|
132
154
|
* ```
|
|
133
155
|
*/
|
|
134
156
|
async embed(inputs, options = {}) {
|
|
135
|
-
const
|
|
136
|
-
if (
|
|
157
|
+
const normalizedInputs = normalizeInputs(inputs);
|
|
158
|
+
if (normalizedInputs.length === 0) {
|
|
137
159
|
throw new Error("At least one input is required");
|
|
138
160
|
}
|
|
139
|
-
if (
|
|
161
|
+
if (normalizedInputs.length > 100) {
|
|
140
162
|
throw new Error("Maximum 100 inputs allowed per request");
|
|
141
163
|
}
|
|
142
164
|
const request = {
|
|
143
|
-
inputs:
|
|
165
|
+
inputs: normalizedInputs,
|
|
144
166
|
model: options.model ?? "public",
|
|
145
167
|
language: options.language ?? "english",
|
|
146
168
|
semanticWeight: options.semanticWeight ?? 0.5
|
package/dist/index.mjs
CHANGED
|
@@ -34,6 +34,20 @@ var APIError = class _APIError extends NeuraLexError {
|
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
// src/client.ts
|
|
37
|
+
function normalizeInputs(inputs) {
|
|
38
|
+
if (typeof inputs === "string") {
|
|
39
|
+
return [{ text: inputs }];
|
|
40
|
+
}
|
|
41
|
+
if (!Array.isArray(inputs)) {
|
|
42
|
+
return [inputs];
|
|
43
|
+
}
|
|
44
|
+
return inputs.map((item) => {
|
|
45
|
+
if (typeof item === "string") {
|
|
46
|
+
return { text: item };
|
|
47
|
+
}
|
|
48
|
+
return item;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
37
51
|
var NeuraLexClient = class {
|
|
38
52
|
/**
|
|
39
53
|
* Create a new NeuraLex client
|
|
@@ -64,7 +78,9 @@ var NeuraLexClient = class {
|
|
|
64
78
|
/**
|
|
65
79
|
* Generate embeddings for the provided input text(s)
|
|
66
80
|
*
|
|
67
|
-
* @param inputs - Text string or array of
|
|
81
|
+
* @param inputs - Text string, EmbeddingInputData, or array of either (max 100).
|
|
82
|
+
* For BYOE (Bring Your Own Embedding) mode, use EmbeddingInputData
|
|
83
|
+
* with the embedding field populated.
|
|
68
84
|
* @param options - Optional parameters
|
|
69
85
|
* @param options.model - Model name (default: "public")
|
|
70
86
|
* @param options.language - Language for lexeme extraction (default: "english")
|
|
@@ -89,18 +105,24 @@ var NeuraLexClient = class {
|
|
|
89
105
|
* semanticWeight: 0.8,
|
|
90
106
|
* model: 'public'
|
|
91
107
|
* });
|
|
108
|
+
*
|
|
109
|
+
* // BYOE mode with pre-computed embeddings
|
|
110
|
+
* const response = await client.embed([
|
|
111
|
+
* { text: 'hello world', embedding: new Array(1024).fill(0.1) },
|
|
112
|
+
* { text: 'server-computed text' }
|
|
113
|
+
* ]);
|
|
92
114
|
* ```
|
|
93
115
|
*/
|
|
94
116
|
async embed(inputs, options = {}) {
|
|
95
|
-
const
|
|
96
|
-
if (
|
|
117
|
+
const normalizedInputs = normalizeInputs(inputs);
|
|
118
|
+
if (normalizedInputs.length === 0) {
|
|
97
119
|
throw new Error("At least one input is required");
|
|
98
120
|
}
|
|
99
|
-
if (
|
|
121
|
+
if (normalizedInputs.length > 100) {
|
|
100
122
|
throw new Error("Maximum 100 inputs allowed per request");
|
|
101
123
|
}
|
|
102
124
|
const request = {
|
|
103
|
-
inputs:
|
|
125
|
+
inputs: normalizedInputs,
|
|
104
126
|
model: options.model ?? "public",
|
|
105
127
|
language: options.language ?? "english",
|
|
106
128
|
semanticWeight: options.semanticWeight ?? 0.5
|