Skip to content

Commit 62dd66d

Browse files
Dan JonesDan Jones
authored andcommitted
Rename methods
1 parent 368bda9 commit 62dd66d

File tree

3 files changed

+37
-13
lines changed

3 files changed

+37
-13
lines changed

src/query/agent.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ it("prepareSearch returns a QueryAgentSearcher", async () => {
114114
systemPrompt: "test system prompt",
115115
});
116116

117-
const searcher = agent.prepareSearch("test query");
117+
const searcher = agent.configureSearch("test query");
118118
expect(searcher).toBeInstanceOf(QueryAgentSearcher);
119119
});
120120

@@ -196,11 +196,11 @@ it("search-only mode success: caches searches and sends on subsequent request",
196196
}) as jest.Mock;
197197

198198
const agent = new QueryAgent(mockClient);
199-
const searcher = agent.prepareSearch("test query", {
199+
const searcher = agent.configureSearch("test query", {
200200
collections: ["test_collection"],
201201
});
202202

203-
const first = await searcher.execute({ limit: 2, offset: 0 });
203+
const first = await searcher.run({ limit: 2, offset: 0 });
204204

205205
expect(first).toEqual<SearchModeResponse<undefined>>({
206206
originalQuery: apiSuccess.original_query,
@@ -234,7 +234,7 @@ it("search-only mode success: caches searches and sends on subsequent request",
234234

235235
// First request should have searches: null (generation request)
236236
expect(capturedBodies[0].searches).toBeNull();
237-
const second = await searcher.execute({ limit: 2, offset: 1 });
237+
const second = await searcher.run({ limit: 2, offset: 1 });
238238
// Second request should include the original searches (execution request)
239239
expect(capturedBodies[1].searches).toEqual(apiSuccess.searches);
240240
// Response mapping should be the same (because response is mocked)
@@ -266,12 +266,12 @@ it("search-only mode failure propagates QueryAgentError", async () => {
266266
) as jest.Mock;
267267

268268
const agent = new QueryAgent(mockClient);
269-
const searcher = agent.prepareSearch("test query", {
269+
const searcher = agent.configureSearch("test query", {
270270
collections: ["test_collection"],
271271
});
272272

273273
try {
274-
await searcher.execute({ limit: 2, offset: 0 });
274+
await searcher.run({ limit: 2, offset: 0 });
275275
} catch (err) {
276276
expect(err).toBeInstanceOf(QueryAgentError);
277277
expect(err).toMatchObject({

src/query/agent.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,21 @@ export class QueryAgent {
188188
}
189189

190190
/**
191-
* Prepare a searcher for the query agent.
191+
* Configure a QueryAgentSearcher for the search-only mode of the query agent.
192+
*
193+
* This returns a configured QueryAgentSearcher, but does not send any requests or
194+
* run the agent. To do that, you should call the `run` method on the searcher.
195+
*
196+
* This allows you to paginate through a consistent results set, as calling the
197+
* `run` method on the searcher multiple times will result in the same underlying
198+
* searches being performed each time.
192199
*
193200
* @param query - The natural language query string for the agent.
194-
* @param options - Additional options for the searcher.
195-
* @returns The searcher for the query agent.
201+
* @param options - Additional options for configuring the searcher.
202+
* @param options.collections - The collections to query. Will override any collections if passed in the constructor.
203+
* @returns A configured QueryAgentSearcher for the search-only mode of the query agent.
196204
*/
197-
prepareSearch<T = undefined>(
205+
configureSearch<T = undefined>(
198206
query: string,
199207
{ collections }: QueryAgentSearchOnlyOptions = {},
200208
): QueryAgentSearcher<T> {

src/query/search.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ import {
1111
/**
1212
* A configured searcher for the QueryAgent.
1313
*
14+
* This is configured using the `QueryAgent.configureSearch` method, which builds this class
15+
* but does not send any requests and run the agent. The configured search can then be run
16+
* using the `run` method. You can paginate through the results set by running the `run` method
17+
* multiple times on the same searcher instance, but with different `limit` / `offset` values;
18+
* this will result in the same underlying searches being performed each time.
19+
*
1420
* Warning:
1521
* Weaviate Agents - Query Agent is an early stage alpha product.
1622
* The API is subject to breaking changes. Please ensure you are using the latest version of the client.
@@ -82,9 +88,19 @@ export class QueryAgentSearcher<T> {
8288
};
8389
}
8490

85-
async execute(
86-
options: SearchExecutionOptions,
87-
): Promise<SearchModeResponse<T>> {
91+
/**
92+
* Run the search-only agent with the given limit and offset values.
93+
*
94+
* Calling this method multiple times on the same QueryAgentSearcher instance will result
95+
* in the same underlying searches being performed each time, allowing you to paginate
96+
* over a consistent results set.
97+
*
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+
* @returns A SearchModeResponse object containing the results, usage, and underlying searches performed.
102+
*/
103+
async run(options: SearchExecutionOptions): Promise<SearchModeResponse<T>> {
88104
if (!this.collections || this.collections.length === 0) {
89105
throw Error("No collections provided to the query agent.");
90106
}

0 commit comments

Comments
 (0)