Skip to content

Commit f78c508

Browse files
Dan JonesDan Jones
authored andcommitted
Address PR comments
1 parent 9749bf2 commit f78c508

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

src/query/agent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,14 @@ export class QueryAgent {
197197
*/
198198
async search<T = undefined>(
199199
query: string,
200-
{ limit, collections }: QueryAgentSearchOnlyOptions = {},
200+
{ limit = 20, collections }: QueryAgentSearchOnlyOptions = {},
201201
): Promise<SearchModeResponse<T>> {
202202
const searcher = new QueryAgentSearcher<T>(this.client, query, {
203203
collections: collections ?? this.collections,
204204
systemPrompt: this.systemPrompt,
205205
agentsHost: this.agentsHost,
206206
});
207-
return searcher.run({ limit: limit ?? 20, offset: 0 });
207+
return searcher.run({ limit, offset: 0 });
208208
}
209209
}
210210

src/query/response/response.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,14 @@ export type MappedSearchModeResponse<T> = {
271271
searchResults: WeaviateReturn<T>;
272272
};
273273

274+
/** Options for the executing a prepared QueryAgent search. */
275+
export type SearchExecutionOptions = {
276+
/** The maximum number of results to return. */
277+
limit?: number;
278+
/** The offset of the results to return, for paginating through query result sets. */
279+
offset?: number;
280+
};
281+
274282
export type SearchModeResponse<T> = MappedSearchModeResponse<T> & {
275-
next: (options?: {
276-
limit?: number;
277-
offset?: number;
278-
}) => Promise<SearchModeResponse<T>>;
283+
next: (options: SearchExecutionOptions) => Promise<SearchModeResponse<T>>;
279284
};

src/query/search.ts

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { WeaviateClient } from "weaviate-client";
2-
import { SearchModeResponse } from "./response/response.js";
2+
import {
3+
SearchExecutionOptions,
4+
SearchModeResponse,
5+
} from "./response/response.js";
36
import { mapSearchOnlyResponse } from "./response/response-mapping.js";
47
import { mapCollections, QueryAgentCollectionConfig } from "./collection.js";
58
import { handleError } from "./response/error.js";
@@ -95,18 +98,19 @@ export class QueryAgentSearcher<T> {
9598
* in the same underlying searches being performed each time, allowing you to paginate
9699
* over a consistent results set.
97100
*
98-
* @param options - Options for executing the search
99-
* @param options.limit - The maximum number of results to return. Defaults to 20 if not specified.
100-
* @param options.offset - The offset to start from. If not specified, retrieval begins from the first object.
101+
* @param [options] - Options for executing the search
102+
* @param [options.limit] - The maximum number of results to return. Defaults to 20 if not specified.
103+
* @param [options.offset] - The offset to start from. If not specified, retrieval begins from the first object.
101104
* @returns A SearchModeResponse object containing the results, usage, and underlying searches performed.
102105
*/
103-
async run(options: SearchExecutionOptions): Promise<SearchModeResponse<T>> {
106+
async run({ limit = 20, offset = 0 }: SearchExecutionOptions = {}): Promise<
107+
SearchModeResponse<T>
108+
> {
104109
if (!this.collections || this.collections.length === 0) {
105110
throw Error("No collections provided to the query agent.");
106111
}
107112
const { requestHeaders, connectionHeaders } = await this.getHeaders();
108113

109-
const { limit = 20, offset = 0 } = options;
110114
const response = await fetch(`${this.agentsHost}/agent/search_only`, {
111115
method: "POST",
112116
headers: requestHeaders,
@@ -128,16 +132,7 @@ export class QueryAgentSearcher<T> {
128132
}
129133
return {
130134
...mappedResponse,
131-
next: async ({ limit: nextLimit = 20, offset: nextOffset = 0 } = {}) =>
132-
this.run({ limit: nextLimit, offset: nextOffset }),
135+
next: async (options: SearchExecutionOptions = {}) => this.run(options),
133136
};
134137
}
135138
}
136-
137-
/** Options for the executing a prepared QueryAgent search. */
138-
export type SearchExecutionOptions = {
139-
/** The maximum number of results to return. */
140-
limit?: number;
141-
/** The offset of the results to return, for paginating through query result sets. */
142-
offset?: number;
143-
};

0 commit comments

Comments
 (0)