Skip to content

Commit 302a718

Browse files
authored
DOC-12705: Natural language requests to Query Service API (#180)
* DOC-12705: Natural language requests to Query Service API * DOC-12770: add documentation for natural_output parameter * Minor fixes
1 parent 9650aa3 commit 302a718

1 file changed

Lines changed: 129 additions & 35 deletions

File tree

docs/modules/n1ql-rest-query/attachments/_query-service.yaml

Lines changed: 129 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,6 @@ paths:
4848
application/x-www-form-urlencoded:
4949
schema:
5050
$ref: "#/components/schemas/Request"
51-
x-codeSamples:
52-
- lang: Shell
53-
label: JSON
54-
source:
55-
$ref: '../../../docs/modules/n1ql-rest-query/examples/exsuccessful.sh'
56-
- lang: Shell
57-
label: Form Data
58-
source:
59-
$ref: '../../../docs/modules/n1ql-rest-query/examples/exformdata.sh'
60-
- lang: Shell
61-
label: Named Parameters
62-
source:
63-
$ref: '../../../docs/modules/n1ql-rest-query/examples/exnamed.sh'
64-
- lang: Shell
65-
label: Numbered Parameters
66-
source:
67-
$ref: '../../../docs/modules/n1ql-rest-query/examples/exnumbered.sh'
68-
- lang: Shell
69-
label: Unnumbered Parameters
70-
source:
71-
$ref: '../../../docs/modules/n1ql-rest-query/examples/expositional.sh'
7251
security:
7352
- Header: []
7453
- Parameter: []
@@ -114,11 +93,6 @@ paths:
11493
The format for URL-encoded parameters is consistent with the syntax for variables according to RFC 6570.
11594
schema:
11695
$ref: "#/components/schemas/Request"
117-
x-codeSamples:
118-
- lang: Shell
119-
label: Read-Only
120-
source:
121-
$ref: '../../../docs/modules/n1ql-rest-query/examples/exreadonly.sh'
12296
security:
12397
- Header: []
12498
- Parameter: []
@@ -163,7 +137,7 @@ components:
163137
schema:
164138
$ref: "#/components/schemas/Response"
165139
example:
166-
$ref: '../../../docs/modules/n1ql-rest-query/examples/exsuccessful.json'
140+
$ref: '../examples/exsuccessful.json'
167141

168142
BadRequest:
169143
description: |-
@@ -180,11 +154,11 @@ components:
180154
n1qlerror:
181155
summary: SQL++ Error
182156
value:
183-
$ref: '../../../docs/modules/n1ql-rest-query/examples/exn1qlerror.json'
157+
$ref: '../examples/exn1qlerror.json'
184158
requesterror:
185159
summary: Request Error
186160
value:
187-
$ref: '../../../docs/modules/n1ql-rest-query/examples/exrequesterror.json'
161+
$ref: '../examples/exrequesterror.json'
188162

189163
Unauthorized:
190164
description: |-
@@ -206,7 +180,7 @@ components:
206180
schema:
207181
$ref: "#/components/schemas/Response"
208182
example:
209-
$ref: '../../../docs/modules/n1ql-rest-query/examples/exnotfound.json'
183+
$ref: '../examples/exnotfound.json'
210184

211185
MethodNotAllowed:
212186
description: |-
@@ -243,7 +217,7 @@ components:
243217
schema:
244218
$ref: "#/components/schemas/Response"
245219
example:
246-
$ref: '../../../docs/modules/n1ql-rest-query/examples/exserviceerror.json'
220+
$ref: '../examples/exserviceerror.json'
247221

248222
schemas:
249223
Request:
@@ -389,8 +363,8 @@ components:
389363
type: string
390364
x-desc-name: encoded_plan
391365
description: |-
392-
In Couchbase Server 6.5 and later, this parameter is ignored and has no effect.
393-
It is included for compatibility with previous versions of Couchbase Server.
366+
In clusters running Couchbase Server 6.5 and later, this parameter is ignored and has no effect.
367+
It is included for compatibility with previous versions.
394368
encoding:
395369
type: string
396370
x-desc-name: encoding
@@ -512,6 +486,112 @@ components:
512486
Currently, only the `default` namespace is available.
513487
x-has-example: true
514488
example: default
489+
natural:
490+
type: string
491+
x-desc-name: natural
492+
x-desc-status: Couchbase Server 8.0
493+
description: |-
494+
The prompt for a natural language request.
495+
The Query Service uses the prompt to generate a SQL++ statement.
496+
497+
If the generated statement is a SELECT statement, the generated statement is returned and executed automatically.
498+
499+
If the generated statement is not a SELECT statement, the generated statement is returned, but not executed.
500+
In this case, you must verify the statement and execute it in a separate request.
501+
502+
Natural language requests use the Couchbase Capella iQ service as a backend.
503+
You must have a Couchbase Capella account to make a natural language request.
504+
505+
This parameter is available in clusters running Couchbase Server 8.0 and later.
506+
507+
To use this parameter, you must also specify the `natural_cred`, `natural_orgid`, and `natural_context` parameters.
508+
If you don't specify all four parameters, the Query Service returns an error.
509+
x-has-example: true
510+
example: Show me count of airlines per country
511+
natural_cred:
512+
type: string
513+
format: password
514+
x-desc-name: natural_cred
515+
x-desc-status: Couchbase Server 8.0
516+
description: |-
517+
The Couchbase Capella credentials for a natural language request, in the form `username:password`.
518+
Be careful not to expose the credentials in log files or other output.
519+
520+
Natural language requests use the Couchbase Capella iQ service as a backend.
521+
You must have a Couchbase Capella account to make a natural language request.
522+
523+
This parameter is available in clusters running Couchbase Server 8.0 and later.
524+
525+
To use this parameter, you must also specify the `natural`, `natural_orgid`, and `natural_context` parameters.
526+
If you don't specify all four parameters, the Query Service returns an error.
527+
x-has-example: true
528+
example: <username>:<password>
529+
natural_orgid:
530+
type: string
531+
format: uuid
532+
x-desc-name: natural_orgid
533+
x-desc-status: Couchbase Server 8.0
534+
description: |-
535+
The Couchbase Capella organization ID for a natural language request.
536+
537+
Natural language requests use the Couchbase Capella iQ service as a backend.
538+
You must have a Couchbase Capella account to make a natural language request.
539+
540+
This parameter is available in clusters running Couchbase Server 8.0 and later.
541+
542+
To use this parameter, you must also specify the `natural`, `natural_cred`, and `natural_context` parameters.
543+
If you don't specify all four parameters, the Query Service returns an error.
544+
natural_context:
545+
type: string
546+
x-desc-name: natural_context
547+
x-desc-status: Couchbase Server 8.0
548+
description: |-
549+
A list of paths specifying keyspaces for a natural language request.
550+
The Query Service infers the schema of each keyspace, in order to give more precise responses from the natural language request.
551+
552+
The parameter may contain up to four paths, separated by commas.
553+
Spaces are allowed.
554+
Each path may be:
555+
556+
* A full path, in the form `bucket.scope.collection` or `namespace:bucket.scope.collection`.
557+
558+
* A path prefix, in the form `namespace:bucket` or `bucket`, to specify the default collection in the default scope.
559+
560+
* A partial path, in the form `collection`.
561+
In this case, you must specify the `query_context` parameter to provide the bucket and scope.
562+
563+
Natural language requests use the Couchbase Capella iQ service as a backend.
564+
You must have a Couchbase Capella account to make a natural language request.
565+
566+
This parameter is available in clusters running Couchbase Server 8.0 and later.
567+
568+
To use this parameter, you must also specify the `natural`, `natural_cred`, and `natural_orgid` parameters.
569+
If you don't specify all four parameters, the Query Service returns an error.
570+
x-has-example: true
571+
example: travel-sample, travel-sample.inventory.airline, airline
572+
natural_output:
573+
type: string
574+
x-desc-name: natural_output
575+
x-desc-status: Couchbase Server 8.0
576+
description: |-
577+
Specifies the required output for a natural language request.
578+
579+
* `sql` &mdash;
580+
The output is a SQL++ statement.
581+
582+
* `jsudf` &mdash;
583+
The output is a `CREATE FUNCTION` statement which you can use to generate a SQL++ managed JavaScript user-defined function.
584+
585+
* `ftssql` &mdash;
586+
The output is a SQL++ statement which can use a Flex index, if available.
587+
588+
Natural language requests use the Couchbase Capella iQ service as a backend.
589+
You must have a Couchbase Capella account to make a natural language request.
590+
591+
This parameter is available in clusters running Couchbase Server 8.0 and later.
592+
x-has-default: true
593+
default: sql
594+
enum: ["sql", "jsudf", "ftssql"]
515595
numatrs:
516596
type: integer
517597
format: int32
@@ -581,7 +661,7 @@ components:
581661
type: string
582662
x-desc-name: prepared
583663
description: |-
584-
_Required_ if `statement` not provided.
664+
_Required_ if `statement` or `natural` not provided.
585665
586666
The name of the prepared SQL++ statement to be executed.
587667
Refer to [EXECUTE][execute] for examples.
@@ -838,7 +918,7 @@ components:
838918
type: string
839919
x-desc-name: statement
840920
description: |-
841-
_Required_ if `prepared` not provided.
921+
_Required_ if `prepared` or `natural` not provided.
842922
843923
Any valid SQL++ statement for a POST request, or a read-only SQL++ statement (SELECT, EXPLAIN) for a GET request.
844924
@@ -1106,6 +1186,12 @@ components:
11061186
clientContextID:
11071187
type: string
11081188
description: The client context ID of the request, if one was supplied &mdash; see `client_context_id` in [Request Parameters](#Request).
1189+
generated_statement:
1190+
type: string
1191+
description: |-
1192+
The generated statement, if the request was a natural language prompt.
1193+
x-has-example: true
1194+
example: SELECT country, COUNT(*) AS `airline_count` FROM `travel-sample`.`inventory`.`airline` AS `a` GROUP BY country
11091195
signature:
11101196
type: object
11111197
description: |-
@@ -1209,9 +1295,11 @@ components:
12091295
properties:
12101296
elapsedTime:
12111297
type: string
1298+
format: duration
12121299
description: The total time taken for the request, that is the time from when the request was received until the results were returned.
12131300
executionTime:
12141301
type: string
1302+
format: duration
12151303
description: The time taken for the execution of the request, that is the time from when query execution started until the results were returned.
12161304
resultCount:
12171305
type: integer
@@ -1221,6 +1309,12 @@ components:
12211309
type: integer
12221310
format: unsigned
12231311
description: The total number of bytes in the results.
1312+
naturalLanguageProcessingTime:
1313+
type: string
1314+
format: duration
1315+
description: |-
1316+
The total time spent processing a natural language request.
1317+
The cumulation of authentication, collecting schema, and time waiting for the response from the LLM, or wait time for the natural language request to be serviced.
12241318
mutationCount:
12251319
type: integer
12261320
description: The number of mutations that were made during the request.

0 commit comments

Comments
 (0)