@anvailabs/proximadb-client 0.3.0 → 0.5.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.
Files changed (44) hide show
  1. package/dist/client.d.ts +4 -4
  2. package/dist/client.d.ts.map +1 -1
  3. package/dist/client.js +92 -5
  4. package/dist/client.js.map +1 -1
  5. package/dist/collection.d.ts +12 -1
  6. package/dist/collection.d.ts.map +1 -1
  7. package/dist/collection.js +33 -3
  8. package/dist/collection.js.map +1 -1
  9. package/dist/generated/schema.d.ts +7508 -2185
  10. package/dist/generated/schema.d.ts.map +1 -1
  11. package/dist/graph.d.ts +3 -3
  12. package/dist/graph.d.ts.map +1 -1
  13. package/dist/graph.js +15 -8
  14. package/dist/graph.js.map +1 -1
  15. package/dist/index.d.mts +3 -0
  16. package/dist/index.d.ts +1 -1
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +4 -1
  19. package/dist/index.js.map +1 -1
  20. package/dist/index.mjs +4 -0
  21. package/package.json +14 -9
  22. package/src/client.ts +195 -32
  23. package/src/collection.ts +38 -3
  24. package/src/generated/schema.ts +7508 -2185
  25. package/src/graph.ts +37 -13
  26. package/src/index.ts +4 -1
  27. package/dist/esm/client.js +0 -674
  28. package/dist/esm/client.js.map +0 -1
  29. package/dist/esm/collection.js +0 -428
  30. package/dist/esm/collection.js.map +0 -1
  31. package/dist/esm/filter.js +0 -228
  32. package/dist/esm/filter.js.map +0 -1
  33. package/dist/esm/generated/schema.js +0 -6
  34. package/dist/esm/generated/schema.js.map +0 -1
  35. package/dist/esm/graph.js +0 -678
  36. package/dist/esm/graph.js.map +0 -1
  37. package/dist/esm/index.js +0 -86
  38. package/dist/esm/index.js.map +0 -1
  39. package/dist/esm/search.js +0 -317
  40. package/dist/esm/search.js.map +0 -1
  41. package/dist/esm/transport.js +0 -33
  42. package/dist/esm/transport.js.map +0 -1
  43. package/dist/esm/types.js +0 -181
  44. package/dist/esm/types.js.map +0 -1
package/src/collection.ts CHANGED
@@ -77,6 +77,24 @@ export interface CollectionHttpClient extends SearchHttpClient {
77
77
  // COLLECTION BUILDER
78
78
  // ============================================================================
79
79
 
80
+ const INDEX_TYPES: readonly string[] = Object.values(IndexType);
81
+
82
+ /**
83
+ * Normalize an index type the way the server reads algorithm names (trimmed,
84
+ * case-insensitive), failing fast on anything that is not an `IndexType`: a
85
+ * plain-JS caller's `"HNSW"` used to be sent as a declared index instead of
86
+ * the default route, and a typo only failed as a server 400.
87
+ */
88
+ export function normalizeIndexType(idx: IndexType | string): IndexType {
89
+ const value = String(idx).trim().toLowerCase();
90
+ if (!INDEX_TYPES.includes(value)) {
91
+ throw new TypeError(
92
+ `unknown index type "${String(idx)}"; expected one of ${INDEX_TYPES.join(", ")}`,
93
+ );
94
+ }
95
+ return value as IndexType;
96
+ }
97
+
80
98
  /**
81
99
  * Builder for creating collections
82
100
  */
@@ -120,10 +138,14 @@ export class CollectionBuilder {
120
138
  }
121
139
 
122
140
  /**
123
- * Set the index type
141
+ * Set the index type.
142
+ *
143
+ * Case-insensitive and whitespace-tolerant, like the server's algorithm
144
+ * names (`"HNSW"` is `IndexType.Hnsw`). An unknown value throws a
145
+ * `TypeError` here, at the call that is wrong, before any request is sent.
124
146
  */
125
147
  index(idx: IndexType): CollectionBuilder {
126
- this.indexValue = idx;
148
+ this.indexValue = normalizeIndexType(idx);
127
149
  return this;
128
150
  }
129
151
 
@@ -159,11 +181,24 @@ export class CollectionBuilder {
159
181
  throw new Error("Dimension is required for collection creation");
160
182
  }
161
183
 
184
+ // TD-RESTGET-1: the server ignores `index_type` "hnsw" (index selection
185
+ // is cost-derived) and rejects any other value, which it never honoured.
186
+ // Send what each choice means: Hnsw keeps the default payload; Flat forces
187
+ // brute force through the routing policy; the others declare that index.
188
+ // `index()` already normalized the value, so these comparisons are exact.
189
+ const index = this.indexValue;
190
+ const indexFields =
191
+ index === IndexType.Hnsw
192
+ ? { index_type: index }
193
+ : index === IndexType.Flat
194
+ ? { index_policy: { mode: "exact" } }
195
+ : { index_configs: [{ algorithm: index, is_primary: true }] };
196
+
162
197
  const request = {
163
198
  name: this.collectionName,
164
199
  dimension: this.dimensionValue,
165
200
  engine: this.engineValue,
166
- index_type: this.indexValue,
201
+ ...indexFields,
167
202
  distance_metric: this.metricValue,
168
203
  description: this.descriptionValue ?? undefined,
169
204
  tags: this.tagsValue.length > 0 ? this.tagsValue : undefined,