@@ -2,6 +2,7 @@ import { WeaviateClient } from "weaviate-client";
22import { QueryAgentResponse } from "./response/response.js" ;
33import { mapResponse } from "./response/response-mapping.js" ;
44import { mapApiResponse } from "./response/api-response-mapping.js" ;
5+ import { mapCollections , QueryAgentCollectionConfig } from "./collection.js" ;
56
67/**
78 * An agent for executing agentic queries against Weaviate.
@@ -13,24 +14,25 @@ import { mapApiResponse } from "./response/api-response-mapping.js";
1314 * For more information, see the [Weaviate Query Agent Docs](https://weaviate.io/developers/agents/query)
1415 */
1516export class QueryAgent {
17+ private collections ?: ( string | QueryAgentCollectionConfig ) [ ] ;
1618 private systemPrompt ?: string ;
1719 private agentsHost : string ;
1820
1921 /**
2022 * Creates a new QueryAgent instance.
2123 *
2224 * @param client - The Weaviate client instance.
23- * @param collections - The collections to query.
2425 * @param options - Additional options for the QueryAgent.
2526 */
2627 constructor (
2728 private client : WeaviateClient ,
28- private collections : string [ ] ,
2929 {
30+ collections,
3031 systemPrompt,
3132 agentsHost = "https://api.agents.weaviate.io" ,
3233 } : QueryAgentOptions = { }
3334 ) {
35+ this . collections = collections ;
3436 this . systemPrompt = systemPrompt ;
3537 this . agentsHost = agentsHost ;
3638 }
@@ -44,8 +46,13 @@ export class QueryAgent {
4446 */
4547 async run (
4648 query : string ,
47- { viewProperties , context, targetVector } : QueryAgentRunOptions = { }
49+ { collections , context } : QueryAgentRunOptions = { }
4850 ) : Promise < QueryAgentResponse > {
51+ const targetCollections = collections ?? this . collections ;
52+ if ( ! targetCollections ) {
53+ throw Error ( "No collections provided to the query agent." ) ;
54+ }
55+
4956 const { host, bearerToken, headers } =
5057 await this . client . getConnectionDetails ( ) ;
5158
@@ -59,11 +66,9 @@ export class QueryAgent {
5966 body : JSON . stringify ( {
6067 headers,
6168 query,
62- collection_names : this . collections ,
63- collection_view_properties : viewProperties ,
69+ collections : mapCollections ( targetCollections ) ,
6470 system_prompt : this . systemPrompt ,
6571 previous_response : context ? mapApiResponse ( context ) : undefined ,
66- target_vector : targetVector ,
6772 } ) ,
6873 } ) ;
6974
@@ -77,6 +82,8 @@ export class QueryAgent {
7782
7883/** Options for the QueryAgent. */
7984export type QueryAgentOptions = {
85+ /** List of collections to query. Will be overriden if passed in the `run` method. */
86+ collections ?: ( string | QueryAgentCollectionConfig ) [ ] ;
8087 /** System prompt to guide the agent's behavior. */
8188 systemPrompt ?: string ;
8289 /** Host of the agents service. */
@@ -85,16 +92,8 @@ export type QueryAgentOptions = {
8592
8693/** Options for the QueryAgent run. */
8794export type QueryAgentRunOptions = {
88- /** List of of property names the agent has the ability to view across all collections. */
89- viewProperties ?: string [ ] ;
90- /**
91- * Target vector for the query if a collection uses named vector.
92- * When multiple collections are provided to the query agent,
93- * a mapping must be used to map collection names to target vectors.
94- */
95- targetVector ?: TargetVector | Record < string , TargetVector > ;
95+ /** List of collections to query. Will override any collections if passed in the constructor. */
96+ collections ?: ( string | QueryAgentCollectionConfig ) [ ] ;
9697 /** Previous response from the agent. */
9798 context ?: QueryAgentResponse ;
9899} ;
99-
100- type TargetVector = string | string [ ] ;
0 commit comments