Skip to content

Commit af4d2a0

Browse files
committed
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 12d8b66 commit af4d2a0

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
@@ -513,6 +487,112 @@ components:
513487
Currently, only the `default` namespace is available.
514488
x-has-example: true
515489
example: default
490+
natural:
491+
type: string
492+
x-desc-name: natural
493+
x-desc-status: Couchbase Server 8.0
494+
description: |-
495+
The prompt for a natural language request.
496+
The Query Service uses the prompt to generate a SQL++ statement.
497+
498+
If the generated statement is a SELECT statement, the generated statement is returned and executed automatically.
499+
500+
If the generated statement is not a SELECT statement, the generated statement is returned, but not executed.
501+
In this case, you must verify the statement and execute it in a separate request.
502+
503+
Natural language requests use the Couchbase Capella iQ service as a backend.
504+
You must have a Couchbase Capella account to make a natural language request.
505+
506+
This parameter is available in clusters running Couchbase Server 8.0 and later.
507+
508+
To use this parameter, you must also specify the `natural_cred`, `natural_orgid`, and `natural_context` parameters.
509+
If you don't specify all four parameters, the Query Service returns an error.
510+
x-has-example: true
511+
example: Show me count of airlines per country
512+
natural_cred:
513+
type: string
514+
format: password
515+
x-desc-name: natural_cred
516+
x-desc-status: Couchbase Server 8.0
517+
description: |-
518+
The Couchbase Capella credentials for a natural language request, in the form `username:password`.
519+
Be careful not to expose the credentials in log files or other output.
520+
521+
Natural language requests use the Couchbase Capella iQ service as a backend.
522+
You must have a Couchbase Capella account to make a natural language request.
523+
524+
This parameter is available in clusters running Couchbase Server 8.0 and later.
525+
526+
To use this parameter, you must also specify the `natural`, `natural_orgid`, and `natural_context` parameters.
527+
If you don't specify all four parameters, the Query Service returns an error.
528+
x-has-example: true
529+
example: <username>:<password>
530+
natural_orgid:
531+
type: string
532+
format: uuid
533+
x-desc-name: natural_orgid
534+
x-desc-status: Couchbase Server 8.0
535+
description: |-
536+
The Couchbase Capella organization ID for a natural language request.
537+
538+
Natural language requests use the Couchbase Capella iQ service as a backend.
539+
You must have a Couchbase Capella account to make a natural language request.
540+
541+
This parameter is available in clusters running Couchbase Server 8.0 and later.
542+
543+
To use this parameter, you must also specify the `natural`, `natural_cred`, and `natural_context` parameters.
544+
If you don't specify all four parameters, the Query Service returns an error.
545+
natural_context:
546+
type: string
547+
x-desc-name: natural_context
548+
x-desc-status: Couchbase Server 8.0
549+
description: |-
550+
A list of paths specifying keyspaces for a natural language request.
551+
The Query Service infers the schema of each keyspace, in order to give more precise responses from the natural language request.
552+
553+
The parameter may contain up to four paths, separated by commas.
554+
Spaces are allowed.
555+
Each path may be:
556+
557+
* A full path, in the form `bucket.scope.collection` or `namespace:bucket.scope.collection`.
558+
559+
* A path prefix, in the form `namespace:bucket` or `bucket`, to specify the default collection in the default scope.
560+
561+
* A partial path, in the form `collection`.
562+
In this case, you must specify the `query_context` parameter to provide the bucket and scope.
563+
564+
Natural language requests use the Couchbase Capella iQ service as a backend.
565+
You must have a Couchbase Capella account to make a natural language request.
566+
567+
This parameter is available in clusters running Couchbase Server 8.0 and later.
568+
569+
To use this parameter, you must also specify the `natural`, `natural_cred`, and `natural_orgid` parameters.
570+
If you don't specify all four parameters, the Query Service returns an error.
571+
x-has-example: true
572+
example: travel-sample, travel-sample.inventory.airline, airline
573+
natural_output:
574+
type: string
575+
x-desc-name: natural_output
576+
x-desc-status: Couchbase Server 8.0
577+
description: |-
578+
Specifies the required output for a natural language request.
579+
580+
* `sql` &mdash;
581+
The output is a SQL++ statement.
582+
583+
* `jsudf` &mdash;
584+
The output is a `CREATE FUNCTION` statement which you can use to generate a SQL++ managed JavaScript user-defined function.
585+
586+
* `ftssql` &mdash;
587+
The output is a SQL++ statement which can use a Flex index, if available.
588+
589+
Natural language requests use the Couchbase Capella iQ service as a backend.
590+
You must have a Couchbase Capella account to make a natural language request.
591+
592+
This parameter is available in clusters running Couchbase Server 8.0 and later.
593+
x-has-default: true
594+
default: sql
595+
enum: ["sql", "jsudf", "ftssql"]
516596
numatrs:
517597
type: integer
518598
format: int32
@@ -582,7 +662,7 @@ components:
582662
type: string
583663
x-desc-name: prepared
584664
description: |-
585-
_Required_ if `statement` not provided.
665+
_Required_ if `statement` or `natural` not provided.
586666
587667
The name of the prepared SQL++ statement to be executed.
588668
Refer to [EXECUTE][execute] for examples.
@@ -840,7 +920,7 @@ components:
840920
type: string
841921
x-desc-name: statement
842922
description: |-
843-
_Required_ if `prepared` not provided.
923+
_Required_ if `prepared` or `natural` not provided.
844924
845925
Any valid SQL++ statement for a POST request, or a read-only SQL++ statement (SELECT, EXPLAIN) for a GET request.
846926
@@ -1105,6 +1185,12 @@ components:
11051185
clientContextID:
11061186
type: string
11071187
description: The client context ID of the request, if one was supplied &mdash; see `client_context_id` in [Request Parameters](#Request).
1188+
generated_statement:
1189+
type: string
1190+
description: |-
1191+
The generated statement, if the request was a natural language prompt.
1192+
x-has-example: true
1193+
example: SELECT country, COUNT(*) AS `airline_count` FROM `travel-sample`.`inventory`.`airline` AS `a` GROUP BY country
11081194
signature:
11091195
type: object
11101196
description: |-
@@ -1208,9 +1294,11 @@ components:
12081294
properties:
12091295
elapsedTime:
12101296
type: string
1297+
format: duration
12111298
description: The total time taken for the request, that is the time from when the request was received until the results were returned.
12121299
executionTime:
12131300
type: string
1301+
format: duration
12141302
description: The time taken for the execution of the request, that is the time from when query execution started until the results were returned.
12151303
resultCount:
12161304
type: integer
@@ -1220,6 +1308,12 @@ components:
12201308
type: integer
12211309
format: unsigned
12221310
description: The total number of bytes in the results.
1311+
naturalLanguageProcessingTime:
1312+
type: string
1313+
format: duration
1314+
description: |-
1315+
The total time spent processing a natural language request.
1316+
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.
12231317
mutationCount:
12241318
type: integer
12251319
description: The number of mutations that were made during the request.

0 commit comments

Comments
 (0)