@maravilla-labs/types 0.2.1 → 0.2.2

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 (2) hide show
  1. package/index.ts +83 -0
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -83,6 +83,87 @@ export interface KvStore {
83
83
 
84
84
  // Database Types
85
85
 
86
+ /** MongoDB-style key direction: `1` ascending, `-1` descending. */
87
+ export type IndexDirection = 1 | -1;
88
+
89
+ /** Whether an index is a regular document index or a vector index. */
90
+ export type IndexKind = 'document' | 'vector';
91
+
92
+ export interface IndexSpec {
93
+ name?: string;
94
+ keys: Array<[string, IndexDirection]> | Record<string, IndexDirection>;
95
+ unique?: boolean;
96
+ sparse?: boolean;
97
+ partial?: Record<string, unknown>;
98
+ expireAfterSeconds?: number;
99
+ }
100
+
101
+ export interface IndexDescriptor {
102
+ collection: string;
103
+ name: string;
104
+ keys: Array<[string, IndexDirection]>;
105
+ unique: boolean;
106
+ sparse: boolean;
107
+ partial?: Record<string, unknown>;
108
+ expireAfterSeconds?: number;
109
+ kind: IndexKind;
110
+ }
111
+
112
+ /** Distance metric used to compare vectors. */
113
+ export type VectorMetric = 'cosine' | 'l2' | 'hamming';
114
+
115
+ /**
116
+ * On-disk storage precision for vectors.
117
+ * - `float32` (default): 4 bytes per dim
118
+ * - `int8`: 1 byte per dim, 4× smaller, typically <2% accuracy loss
119
+ * - `bit`: 1 bit per dim, 32× smaller; requires metric='hamming'
120
+ */
121
+ export type VectorStorage = 'float32' | 'int8' | 'bit';
122
+
123
+ /** Query shape: single vector or an array of vectors (ColBERT-style). */
124
+ export type VectorQueryMode = 'single' | 'late-interaction';
125
+
126
+ /** How multi-vector distances are aggregated per document. */
127
+ export type VectorAggregation = 'max-sim' | 'sum';
128
+
129
+ /** Spec used to declare a vector index on a collection field. */
130
+ export interface VectorIndexSpec {
131
+ field: string;
132
+ dimensions: number;
133
+ metric?: VectorMetric;
134
+ storage?: VectorStorage;
135
+ matryoshka?: boolean;
136
+ multiVector?: boolean;
137
+ }
138
+
139
+ /** Metadata for a registered vector index. */
140
+ export interface VectorIndexDescriptor {
141
+ collection: string;
142
+ field: string;
143
+ dimensions: number;
144
+ metric: VectorMetric;
145
+ storage: VectorStorage;
146
+ matryoshka: boolean;
147
+ multiVector: boolean;
148
+ }
149
+
150
+ /** Vector search clause riding inside DbFindOptions. */
151
+ export interface VectorQuery {
152
+ field: string;
153
+ value: number[] | number[][];
154
+ k: number;
155
+ metric?: VectorMetric;
156
+ minScore?: number;
157
+ queryMode?: VectorQueryMode;
158
+ aggregation?: VectorAggregation;
159
+ }
160
+
161
+ /** Document returned by a vector search with similarity metadata attached. */
162
+ export type VectorSearchHit = Record<string, any> & {
163
+ _score: number;
164
+ _distance: number;
165
+ };
166
+
86
167
  /**
87
168
  * Database find options
88
169
  */
@@ -91,6 +172,8 @@ export interface DbFindOptions {
91
172
  skip?: number;
92
173
  sort?: Record<string, 1 | -1>;
93
174
  projection?: Record<string, 1 | 0>;
175
+ /** Hybrid metadata + vector search clause. */
176
+ vector?: VectorQuery;
94
177
  }
95
178
 
96
179
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maravilla-labs/types",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "TypeScript definitions for Maravilla Runtime platform APIs",
5
5
  "main": "index.ts",
6
6
  "types": "index.ts",