neuralex 0.1.0 → 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 CHANGED
@@ -2,6 +2,21 @@
2
2
 
3
3
  Official TypeScript/JavaScript client library for the [NeuraLex](https://neuralex.ca) API.
4
4
 
5
+ ## What is NeuraLex?
6
+
7
+ NeuraLex is a next-generation embedding API that combines **semantic understanding** with **term-based precision** to deliver superior search and retrieval performance. Unlike traditional embedding models that rely solely on neural networks, NeuraLex uses a hybrid approach that preserves exact keyword matching while capturing semantic meaning.
8
+
9
+ This hybrid architecture delivers:
10
+ - ✅ **Better recall** - Captures both exact terms and semantic meaning
11
+ - ✅ **Reduced false positives (disambiguation)** - Term-based component filters irrelevant semantic matches
12
+ - ✅ **Configurable precision** - Adjust the balance for your use case
13
+
14
+ ### Learn More
15
+
16
+ - 📄 [NeuraSearch Whitepaper](https://neuralex.ca/neurasearch-whitepaper) - Technical deep dive into the hybrid approach
17
+ - 📊 [Performance Analysis](https://neuralex.ca/neurasearch-analysis) - Benchmark results and comparisons
18
+ - 📖 [API Documentation](https://neuralex.ca/docs/api) - Complete API reference
19
+
5
20
  ## Installation
6
21
 
7
22
  ```bash
@@ -39,6 +54,7 @@ console.log(`First 5 values: ${embedding.slice(0, 5)}`);
39
54
  - ✅ Configurable semantic/term-based balance
40
55
  - ✅ Batch embedding support (up to 100 inputs)
41
56
  - ✅ Tree-shakeable ESM and CommonJS builds
57
+ - ✅ BYOE (Bring Your Own Embedding) mode support
42
58
 
43
59
  ## Usage
44
60
 
@@ -92,6 +108,30 @@ const response = await client.embed('Python programming', {
92
108
  });
93
109
  ```
94
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
+
95
135
  ### Error Handling
96
136
 
97
137
  ```typescript
@@ -160,7 +200,7 @@ Generate embeddings for text input(s).
160
200
 
161
201
  **Parameters:**
162
202
 
163
- - `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)
164
204
  - `options` (object, optional):
165
205
  - `model` (string): Model name (default: "public")
166
206
  - `language` (string): Language for lexeme extraction (default: "english")
@@ -170,6 +210,17 @@ Generate embeddings for text input(s).
170
210
 
171
211
  ### Types
172
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
+
173
224
  #### `EmbeddingResponse`
174
225
 
175
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: string[];
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: string | string[], options?: {
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: string[];
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: string | string[], options?: {
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 text strings to embed (max 100)
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 inputArray = Array.isArray(inputs) ? inputs : [inputs];
136
- if (inputArray.length === 0) {
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 (inputArray.length > 100) {
161
+ if (normalizedInputs.length > 100) {
140
162
  throw new Error("Maximum 100 inputs allowed per request");
141
163
  }
142
164
  const request = {
143
- inputs: inputArray,
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 text strings to embed (max 100)
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 inputArray = Array.isArray(inputs) ? inputs : [inputs];
96
- if (inputArray.length === 0) {
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 (inputArray.length > 100) {
121
+ if (normalizedInputs.length > 100) {
100
122
  throw new Error("Maximum 100 inputs allowed per request");
101
123
  }
102
124
  const request = {
103
- inputs: inputArray,
125
+ inputs: normalizedInputs,
104
126
  model: options.model ?? "public",
105
127
  language: options.language ?? "english",
106
128
  semanticWeight: options.semanticWeight ?? 0.5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neuralex",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Official TS/JS client library for NeuraLex API",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",