Skip to content

Commit a7f980c

Browse files
Dan JonesDan Jones
authored andcommitted
Make searcher generic to support generic WeaviateReturn
1 parent 04d8150 commit a7f980c

File tree

5 files changed

+14
-14
lines changed

5 files changed

+14
-14
lines changed

src/query/agent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,10 @@ export class QueryAgent {
194194
* @param options - Additional options for the searcher.
195195
* @returns The searcher for the query agent.
196196
*/
197-
prepareSearch(
197+
prepareSearch<T = undefined>(
198198
query: string,
199199
{ collections }: QueryAgentSearchOnlyOptions = {},
200-
): QueryAgentSearcher {
200+
): QueryAgentSearcher<T> {
201201
return new QueryAgentSearcher(this.client, query, {
202202
collections: collections ?? this.collections,
203203
systemPrompt: this.systemPrompt,

src/query/response/api-response.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,10 @@ export type ApiSource = {
180180
collection: string;
181181
};
182182

183-
export type ApiSearchModeResponse = {
183+
export type ApiSearchModeResponse<T> = {
184184
original_query: string;
185185
searches?: ApiSearchResult[];
186186
usage: ApiUsage;
187187
total_time: number;
188-
search_results: WeaviateReturn<undefined>;
188+
search_results: WeaviateReturn<T>;
189189
};

src/query/response/response-mapping.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,14 +302,14 @@ export const mapResponseFromSSE = (
302302
};
303303
};
304304

305-
export const mapSearchOnlyResponse = (
306-
response: ApiSearchModeResponse,
305+
export const mapSearchOnlyResponse = <T>(
306+
response: ApiSearchModeResponse<T>,
307307
): {
308-
mappedResponse: SearchModeResponse;
308+
mappedResponse: SearchModeResponse<T>;
309309
apiSearches: ApiSearchResult[] | undefined;
310310
} => {
311311
const apiSearches = response.searches;
312-
const mappedResponse: SearchModeResponse = {
312+
const mappedResponse: SearchModeResponse<T> = {
313313
originalQuery: response.original_query,
314314
searches: apiSearches ? mapInnerSearches(apiSearches) : undefined,
315315
usage: mapUsage(response.usage),

src/query/response/response.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,10 @@ export type StreamedTokens = {
263263
delta: string;
264264
};
265265

266-
export type SearchModeResponse = {
266+
export type SearchModeResponse<T> = {
267267
originalQuery: string;
268268
searches?: SearchResult[];
269269
usage: Usage;
270270
totalTime: number;
271-
searchResults: WeaviateReturn<undefined>;
271+
searchResults: WeaviateReturn<T>;
272272
};

src/query/search.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
*
1818
* For more information, see the [Weaviate Query Agent Docs](https://weaviate.io/developers/agents/query)
1919
*/
20-
export class QueryAgentSearcher {
20+
export class QueryAgentSearcher<T> {
2121
//private headers: Record<string, string> = {};
2222
//private connectionHeaders: HeadersInit | undefined;
2323
private agentsHost: string;
@@ -84,7 +84,7 @@ export class QueryAgentSearcher {
8484
};
8585
}
8686

87-
async execute(options: SearchExecutionOptions): Promise<SearchModeResponse> {
87+
async execute(options: SearchExecutionOptions): Promise<SearchModeResponse<T>> {
8888
if (!this.collections || this.collections.length === 0) {
8989
throw Error("No collections provided to the query agent.");
9090
}
@@ -101,9 +101,9 @@ export class QueryAgentSearcher {
101101
if (!response.ok) {
102102
await handleError(await response.text());
103103
}
104-
const parsedResponse = (await response.json()) as ApiSearchModeResponse;
104+
const parsedResponse = (await response.json()) as ApiSearchModeResponse<T>;
105105
const { mappedResponse, apiSearches } =
106-
mapSearchOnlyResponse(parsedResponse);
106+
mapSearchOnlyResponse<T>(parsedResponse);
107107
// If we successfully mapped the searches, cache them for the next request.
108108
// Since this cache is a private internal value, there's not point in mapping
109109
// back and forth between the exported and API types, so we cache apiSearches

0 commit comments

Comments
 (0)