@@ -97,13 +97,14 @@ function buildEmbedder(config: EmbedderConfig): EmbedderFunction | null {
9797 * @param embedder - The resolved embedder function
9898 * @returns The modified where clause
9999 */
100- export async function autoEmbedWhere (
101- where : Record < string , unknown > ,
100+ export async function autoEmbedWhere < T extends object > (
101+ where : T ,
102102 vectorFieldNames : string [ ] ,
103103 embedder : EmbedderFunction
104- ) : Promise < Record < string , unknown > > {
104+ ) : Promise < T > {
105+ const rec = where as unknown as Record < string , unknown > ;
105106 for ( const fieldName of vectorFieldNames ) {
106- const fieldValue = where [ fieldName ] ;
107+ const fieldValue = rec [ fieldName ] ;
107108 if ( fieldValue && typeof fieldValue === 'object' ) {
108109 const input = fieldValue as Record < string , unknown > ;
109110 // If 'vector' is a string, embed it
@@ -116,7 +117,7 @@ export async function autoEmbedWhere(
116117 // Shorthand: --where.vectorEmbedding "text" with --auto-embed
117118 // becomes { vector: [embedded], metric: 'COSINE' }
118119 const embedding = await embedder ( fieldValue ) ;
119- where [ fieldName ] = { vector : embedding } ;
120+ rec [ fieldName ] = { vector : embedding } ;
120121 }
121122 }
122123 return where ;
@@ -141,17 +142,18 @@ export async function autoEmbedWhere(
141142 * @param embedder - The resolved embedder function
142143 * @returns The modified data object with text values replaced by vectors
143144 */
144- export async function autoEmbedInput (
145- data : Record < string , unknown > ,
145+ export async function autoEmbedInput < T extends object > (
146+ data : T ,
146147 vectorFieldNames : string [ ] ,
147148 embedder : EmbedderFunction
148- ) : Promise < Record < string , unknown > > {
149+ ) : Promise < T > {
150+ const rec = data as unknown as Record < string , unknown > ;
149151 for ( const fieldName of vectorFieldNames ) {
150- const fieldValue = data [ fieldName ] ;
152+ const fieldValue = rec [ fieldName ] ;
151153 if ( typeof fieldValue === 'string' ) {
152154 // Text string → embed to vector array
153155 const embedding = await embedder ( fieldValue ) ;
154- data [ fieldName ] = embedding ;
156+ rec [ fieldName ] = embedding ;
155157 }
156158 // If it's already an array (pre-computed vector), leave it as-is
157159 }
0 commit comments