vania-janet/multiturn-rag-retrieval-data huggingface dataset:
service.postView({
db: 'users',
ddoc: 'allusers',
view: 'getVerifiedEmails',
descending: true,
startKey: 'beta',
endKey: 'alpha'
}).then(response => {
console.log(response.result);
});

from ibmcloudant.cloudant_v1 import CloudantV1

service = CloudantV1.new_instance()

response = service.post_view(
db='users',
ddoc='allusers',
view='getVerifiedEmails',
descending=True,
start_key='beta',
end_key='alpha'
).get_result()

print(response)

postViewOptions := service.NewPostViewOptions(
"users",
"allusers",
"getVerifiedEmails",
)

postViewOptions.SetDescending(true)
postViewOptions.StartKey = "beta"
postViewOptions.EndKey = "alpha"

viewResult, response, err := service.PostView(postViewOptions)
if err != nil {
panic(err)
}

b, _ := json.MarshalIndent(viewResult, "", " ")
fmt.Println(string(b))

The previous Go example requires the following import block:

import (
"encoding/json"
"fmt"
"github.com/IBM/cloudant-go-sdk/cloudantv1"
)

All Go examples require the service object to be initialized. For more information, see the API documentation's [Authentication section](https://cloud.ibm.com/apidocs/cloudant?code=goauthentication-with-external-configuration) for examples.





 Querying a view by using a list of keys
All Go examples require the service object to be initialized. For more information, see the API documentation's [Authentication section](https://cloud.ibm.com/apidocs/cloudant?code=goauthentication-with-external-configuration) for examples.

For example, if you have a database that returns one result when you use a start_key of alpha and an end_key of beta, you would get a 400 (Bad request) error with a reversed order. The reason is that the entries in the view are reversed before the key filter is applied.

See the example that uses HTTP to illustrate why reversing the order of start_key and end_key might return a query parse error:

GET $SERVICE_URL/$DATABASE/_design/$DDOC/_view/$VIEW_NAME?descending=true&start_key="alpha"&end_key="beta" HTTP/1.1

See the example illustrating why reversing the order of start_key and end_key might cause a 400 error.

Client libraries use POST method instead of GET because they have the same behavior.



* Curl
* Java
* Node
* Python
* Go



curl -X GET "$SERVICE_URL/users/_design/allusers/_view/getVerifiedEmails?descending=true&start_key="alpha"&end_key="beta""

import com.ibm.cloud.cloudant.v1.Cloudant;
import com.ibm.cloud.cloudant.v1.model.PostViewOptions;
import com.ibm.cloud.cloudant.v1.model.ViewResult;

Cloudant service = Cloudant.newInstance();

PostViewOptions viewOptions = new PostViewOptions.Builder()
.db("users")
.ddoc("allusers")
.view("getVerifiedEmails")
.descending(true)
.startKey("alpha")
.endKey("beta")
.build();

ViewResult response =
service.postView(viewOptions).execute()
Get the name of the credentials that are defined for the service instance you got in the previous step.

ibmcloud resource service-keys --instance-name Cloudant-gm

The following example shows possible output for the esource service-keys command.

Name State Created At
Service credentials-1 active Sat Oct 27 03:26:52 UTC 2018
Service credentials-2 active Sun Jan 27 22:14:58 UTC 2019
5. Bind the service to the package you created in step one.

ibmcloud fn service bind cloudantnosqldb myCloudant --instance Cloudant-gm --keyname 'Service credentials-1'
6. Verify that the credentials are successfully bound.

ibmcloud fn package get myCloudant parameters

The following example shows possible output for the package get command.

ok: got package myCloudant, displaying field parameters
{
"parameters": [
{
"key": "serviceName",
"value": "cloudantNoSQLDB"
},
{
"key": "apihost",
"value": "us-south.functions.cloud.ibm.com"
},
{
"key": "__bx_creds",
"value": {
"cloudantnosqldb": {
"apikey": "Service apikey]",
"credentials": "Service credentials-1",
"iam_apikey_description": "Service description]",
"iam_apikey_name": "Service apikey name]",
"iam_role_crn": "Service role crn]",
"iam_serviceid_crn": "Service id crn]",
"instance": "Cloudant-gm",
"url": "Service url]",
"username": "Service username]"
}
}
}
],
}
In this manifest.yml file, random-route: true generates a random route for your app to prevent your route from colliding with others. If you choose to, you can replace random-route: true with host: <myChosenHostName>, supplying a host name of your choice.





 Step 4: Deploy the app 

You can use the IBM Cloud CLI to deploy apps to IBM Cloud.



1. Log in to your IBM Cloud account, and select an API endpoint.

ibmcloud login

If you have a federated user ID, instead use the following command to log in with your single sign-on ID. See [Logging in with a federated ID](https://cloud.ibm.com/docs/account?topic=account-federated_id) for more information.

ibmcloud login --sso

Target a Cloud Foundry org and space:

ibmcloud target --cf

If you don't have an org or a space set up, see [Adding orgs and spaces](https://cloud.ibm.com/docs/account?topic=account-orgsspacesusers).
2. From within the get-started-node directory, push your app to IBM Cloud.

ibmcloud cf push



Deploying your app can take a few minutes. When deployment completes, you'll see a message that your app is running. View your app at the URL listed in the output of the push command, or view both the app deployment status and the URL by running the following command:

ibmcloud cf apps

You can also go to the IBM Cloud [resource list](https://cloud.ibm.com/resources) to view your app.

You can troubleshoot errors in the deployment process by using the ibmcloud cf logs <Your-App-Name> --recent command.





 Step 5: Add a database 

Next, we'll add an IBM Cloudant NoSQL database to this app and set up the app so that it can run locally and on IBM Cloud.



1. In your browser, log in to IBM Cloud and go to the Dashboard. Select Create resource.
2.
* [Plan data storage](https://cloud.ibm.com/docs/openshift?topic=openshift-storage-plan). Especially for multizone clusters, consider using a cloud service such as [IBM Cloudant](https://cloud.ibm.com/docs/Cloudant?topic=Cloudant-getting-started-with-cloudant) or [IBM Cloud Object Storage](https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-getting-started-cloud-object-storage).
* For multizone clusters, enable a [load balancer service](https://cloud.ibm.com/docs/openshift?topic=openshift-loadbalancermulti_zone_config) or the Ingress [multizone load balancer](https://cloud.ibm.com/docs/containers?topic=containers-managed-ingress-about) to expose your apps publicly.
- name: GetStartedGo
random-route: true
memory: 128M
buildpack: go_buildpack

In this manifest.yml file, random-route: true generates a random route for your app to prevent your route from colliding with others. If you choose to, you can replace random-route: true with host: myChosenHostName, supplying a host name of your choice.





 Step 4: Deploy the app 

You can use the IBM Cloud CLI to deploy apps.



1. Log in to your IBM Cloud account, and select an API endpoint.

ibmcloud login

If you have a federated user ID, instead use the following command to log in with your single sign-on ID. See [Logging in with a federated ID](https://cloud.ibm.com/docs/account?topic=account-federated_id) to learn more.

ibmcloud login --sso
2. Target a Cloud Foundry org and space:

ibmcloud target --cf

If you don't have an org or a space set up, see [Adding orgs and spaces](https://cloud.ibm.com/docs/account?topic=account-orgsspacesusers).
3. From within the get-started-go directory, push your app to IBM Cloud

ibmcloud cf push

This can take a minute. If there is an error in the deployment process you can use the command ibmcloud cf logs <Your-App-Name> --recent to troubleshoot.



When deployment completes you should see a message indicating that your app is running. View your app at the URL listed in the output of the push command. You can also issue the following command to view your app's status and see the URL.

ibmcloud cf apps

You can also go to the IBM Cloud [resource list](https://cloud.ibm.com/resources) to view your app.





 Step 5: Add a database 

Next, we'll add an IBM Cloudant NoSQL database to this app and set up the app so that it can run locally and on IBM Cloud.
}).then(response => {
console.log(response.result);
});

from ibmcloudant.cloudant_v1 import CloudantV1

service = CloudantV1.new_instance()

response = service.get_replication_document(
conflicts=True,
doc_id='$DOCID'
).get_result()

print(response)

getReplicationDocumentOptions := service.NewGetReplicationDocumentOptions(
"$DOCID",
)

replicationDocument, response, err := service.GetReplicationDocument(getReplicationDocumentOptions)
if err != nil {
panic(err)
}

replicationDocument.Conflicts = core.BoolPtr(true)

b, _ := json.MarshalIndent(replicationDocument, "", " ")
fmt.Println(string(b))

The previous Go example requires the following import block:

import (
"encoding/json"
"fmt"
"github.com/IBM/cloudant-go-sdk/cloudantv1"
"github.com/IBM/go-sdk-core/core"
)

All Go examples require the service object to be initialized. For more information, see the API documentation's [Authentication section](https://cloud.ibm.com/apidocs/cloudant?code=goauthentication-with-external-configuration) for examples.







 Cancel all replications 

If you want to cancel all replications and start with a new, clean _replicator database, delete then re-create the replicator database.

See the following HTTP to remove and re-create the _replicator database:

DELETE /_replicator HTTP/1.1
HOST: $SERVICE_URL
Authorization: ...

PUT /_replicator HTTP/1.1
HOST: $SERVICE_URL
Authorization: ...



 Delete the replicator database
ibmcloud fn service bind SERVICE ACTION_NAME [--instance INSTANCE_NAME] [--keyname CREDENTIALS_NAME]

For example, to bind an IBM Cloudant service instance to an action called hello, run the following command.

ibmcloud fn service bind cloudantnosqldb hello --instance My-Cloudant --keyname cloudant-my1-creds

If your action is not found, try adding the package name to the command: demohello. Note that if there's only one instance of service type cloudantnosqldb and one service key, the --instance and --keyname options can be omitted.

If you receive the message Unable to refresh user access token: CloudFoundry API endpoint is not set, try running ibmcloud target --cf with no arguments and then running the command again.

Example output

Credentials 'cloudant-my1-creds' from 'cloudantnosqldb' service instance 'My-Cloudant' bound to 'hello'.
4. Verify that the credentials are successfully bound. The action that the service is bound to doesn't support any custom flags, but does support the debug and verbose flags.

ibmcloud fn action get hello parameters

Example output

"key": "__bx_creds",
"value": {
"cloudantnosqldb": {
"apikey": "ABC123ABC123abc123abc123ABC123ABC123abc123",
"credentials": "cloudant-my1-creds",
...
}
}

In this example, the credentials for the Cloudant service, along with any other credentials for other service types belong to a parameter named __bx_creds. The action code can access the necessary information by getting the __bx_creds parameter.

For example, in nodejs, you can use the following code to get the API key for the Cloudant service in the previous sample.

function main(params) {
Getting started with PHP 

IBM® Cloud Foundry is deprecated and no longer supported as of 1 June 2023. For more information, see the [deprecation details](https://cloud.ibm.com/docs/cloud-foundry-public?topic=cloud-foundry-public-deprecationdep_details).

Congratulations, you deployed a Hello World sample app on IBM Cloud®! To get started, follow this step-by-step guide. Or, [download the sample code](https://github.com/IBM-Cloud/get-started-php) and explore on your own.

By following this getting started tutorial, you'll set up a development environment, deploy an app locally on IBM Cloud®, and integrate a database service in your app.

Throughout these docs, references to the Cloud Foundry CLI are now updated to the IBM Cloud CLI! The IBM Cloud CLI has the same familiar Cloud Foundry commands, but with better integration with IBM Cloud accounts and other services. Learn more about getting started with the IBM Cloud CLI in this tutorial.



 Before you begin 

You'll need the following:



* [IBM Cloud account](https://cloud.ibm.com/registration)
* [IBM Cloud CLI](https://cloud.ibm.com/docs/cli?topic=cli-install-ibmcloud-cli)
* [Git](https://git-scm.com/downloads)
* [PHP](http://php.net/downloads.php)
* [Composer](https://getcomposer.org/download/)







 Step 1: Clone the sample app 

First, clone the repo and change the directory to where the sample app is located.

git clone https://github.com/IBM-Cloud/get-started-php

cd get-started-php





 Step 2: Run the app locally 



1. Install dependencies.

php composer.phar install
2. Run the app locally.

php -S localhost:8000
3.
To take advantage of the tagging, export, retention, and other features, you need to use one of the [paid plans](https://cloud.ibm.com/docs/log-analysis?topic=log-analysis-service_plans).



 HIPAA 

IBM Cloud Log Analysis does not currently offer a HIPAA-compliant plan for the service.

Use caution when you configure the platform service logs, since this setting can impact other services that require HIPAA compliance.







 Using IBM Cloud Log Analysis 

Once logs are being live-streamed, each log can be expanded to a detailed view by clicking the arrow by the timestamp.

The expanded view has some handy, color-coded fields to help you parse your logs.



Table 2. Line identifiers

 Line Identifiers Description 

 Source The region the logs are being sent from. 
 App The CRN of your database deployment that is sending the logs. 





Table 3. Log lines

 Log Lines Description 

 accountName The IBM Cloudant account identifier that you can use when you contact support about your environment. 
 httpMethod Request method, for example, GET, PUT, to indicate the action to be performed for a specific resource. 
 httpRequest The URL path for the HTTP request. 
 bytesRead The size of the response body. 
 clientIp The IP address of the originating request. 
 clientPort The port address for the originating request. 
 statusCode The HTTP status code returned from IBM Cloudant. For more information, see [HTTP status codes](https://cloud.ibm.com/apidocs/cloudantlist-of-http-codes). 
 terminationState Session termination indicator for TCP and HTTP logs. For more information, see [Session state at disconnection](https://cbonte.github.io/haproxy-dconv/1.7/configuration.html8.5). 
 dbName The IBM Cloudant database name targeted by the HTTP Request. 
 dbRequest The database request endpoint. 
 userAgent Software that is acting on behalf of the user, such as a browser or client library. 
 sslVersion The version of Transport Layer Security that the request is using.
Create a rule named cloudantRule to connect the cloudantChange action to the cloudantTrigger that you created earlier.

ibmcloud fn rule create cloudantRule cloudantTrigger cloudantChange
5. In another window, start polling so that you can see when activations occur.

ibmcloud fn activation poll
6. From the IBM Cloudant dashboard, either modify an existing document or create one.
7. Observe activations for the cloudantTrigger trigger for each document change.

Example activation of the cloudantTrigger

Activation: 'cloudantTrigger' (ef6605cc05e04589a605cc05e04589d8)
[
"{"statusCode":0,"success":true,"activationId":"6067ed0d28774a68a7ed0d28771a684d","rule":" . <namespace_ID>/cloudantRule","action":"<namespace_ID>/cloudantChange"}"
]

Activation: 'cloudantChange' (6067ed0d28774a68a7ed0d28771a684d)
[
"2019-06-24T16:46:10.428643Z stdout: { changes: { rev: '19-f7f6d8607d6381d224321acfcfb8887e' } ] ! ! ! ! ,",
"2019-06-24T16:46:10.428693Z stdout: dbname: 'test',",
"2019-06-24T16:46:10.428697Z stdout: id: '6ca436c44074c4c2aa6a40c9a188b348',",
Managing tasks 

Creating new indexes over lots of data or replicating a large database can take quite a while.

How can you determine whether your tasks are progressing or completed? The [_active_tasks endpoint](https://cloud.ibm.com/docs/Cloudant?topic=Cloudant-active-tasksactive-tasks) provides information about all ongoing tasks. However, if you start numerous tasks, some of them might be scheduled to run later and don't show up under _active_tasks until they start.

See the following examples of SDK and curl code:



* Curl
* Java
* Node
* Python
* Go



curl "$SERVICE_URL/_active_tasks"

import com.ibm.cloud.cloudant.v1.Cloudant;
import com.ibm.cloud.cloudant.v1.model.ActiveTask;

Cloudant service = Cloudant.newInstance();

List<ActiveTask> response =
service.getActiveTasks().execute().getResult();

System.out.println(response);

const { CloudantV1 } = require('@ibm-cloud/cloudant');

const service = CloudantV1.newInstance({});

service.getActiveTasks().then(response => {
console.log(response.result);
});

from ibmcloudant.cloudant_v1 import CloudantV1

service = CloudantV1.new_instance()

response = service.get_active_tasks().get_result()

print(response)

getActiveTasksOptions := service.NewGetActiveTasksOptions()

activeTask, response, err := service.GetActiveTasks(getActiveTasksOptions)
if err != nil {
panic(err)
}

b, _ := json.MarshalIndent(activeTask, "", " ")
fmt.Println(string(b))
console.log(response.result);
});

from ibmcloudant.cloudant_v1 import CloudantV1

service = CloudantV1.new_instance()

response = service.delete_database(db='_replicator').get_result()

print(response)

deleteDatabaseOptions := service.NewDeleteDatabaseOptions(
"_replicator",
)

ok, response, err := service.DeleteDatabase(deleteDatabaseOptions)
if err != nil {
panic(err)
}

b, _ := json.MarshalIndent(ok, "", " ")
fmt.Println(string(b))

The previous Go example requires the following import block:

import (
"encoding/json"
"fmt"
"github.com/IBM/cloudant-go-sdk/cloudantv1"
)

All Go examples require the service object to be initialized. For more information, see the API documentation's [Authentication section](https://cloud.ibm.com/apidocs/cloudant?code=goauthentication-with-external-configuration) for examples.





 Re-create the replicator database 

See the following example to re-create the _replicator database:



* Curl
* Java
* Node
* Python
* Go



curl -X PUT "$SERVICE_URL/_replicator"

import com.ibm.cloud.cloudant.v1.Cloudant;
import com.ibm.cloud.cloudant.v1.model.Ok;
import com.ibm.cloud.cloudant.v1.model.PutDatabaseOptions;

Cloudant service = Cloudant.newInstance();

PutDatabaseOptions databaseOptions = new PutDatabaseOptions.Builder()
.db("_replicator")
.build();

Ok response =
service.putDatabase(databaseOptions).execute()
Before you begin, [create an action](https://cloud.ibm.com/docs/openwhisk?topic=openwhisk-actions) and [define credentials](https://cloud.ibm.com/docs/account?topic=account-externalappexternalapp) for the service that you want to bind to the action.



1. Get the list of available service keys of services that you want to bind to an action or package.

ibmcloud resource service-keys

Example output

Name State Created At
Service credentials-1 active Tue Sep 17 15:50:43 UTC 2019
cloudant-my1-creds active Tue Sep 17 14:30:08 UTC 2019

To find more details, use --output json.

If you know the service name or ID, you can use the --instance-name NAME option to get only the subset of keys for a specific service instance. For example:

ibmcloud resource service-keys --instance-name My-Cloudant
2. Get details of a selected service key.

ibmcloud resource service-key <service_key_name>

Example output

Name: cloudant-my1-creds
ID: crn:v1:bluemix:public:cloudantnosqldb:eu-de:a/123456789012345678901234567890ab:f6f38f72-95af-4699-842c-4cac2a1ea19e:resource-key:5dab35d4-fe20-433e-9cb9-7ae4d93887d5
Created At: Wed Nov 28 16:30:08 UTC 2018
State: active
Credentials:
apikey: ABC123ABC123abc123abc123ABC123ABC123abc123
...
3. Bind the service to an action or package.
Use the IBM Cloudant Dashboard, or see the [authorization](https://cloud.ibm.com/docs/Cloudant?topic=Cloudant-work-with-your-accountauthorization) information for details of how to grant permissions programmatically.





 Step 4. Set up replications 

Replications in IBM Cloudant are always uni-directional: from one database to another database. To replicate both ways between two databases, two replications are required, one for each direction.

A replication is created in each account that uses the API Key that is created [earlier](https://cloud.ibm.com/docs/Cloudant?topic=Cloudant-configuring-ibm-cloudant-for-cross-region-disaster-recoverystep-2-create-an-api-key-for-your-replications).

First, create a replication from database myaccount-dc1.cloudant.com/mydb to database myaccount-dc2.cloudant.com/mydb.

curl -XPOST "https://myaccount-dc1.cloudant.com/_replicator"
-u myaccount-dc1
-H "Content-Type: application/json"
-d '{ "_id": "mydb-myaccount-dc1-to-myaccount-dc2",
"source": "https://ble...igl:YPN...Tfi@myaccount-dc1.cloudant.com/mydb",
"target": "https://ble...igl:YPN...Tfi@myaccount-dc2.cloudant.com/mydb",
"continuous": true
}'

Next, create a replication from database myaccount-dc2.cloudant.com/mydb to database myaccount-dc1.cloudant.com/mydb.

curl -XPOST "https://myaccount-dc2.cloudant.com/_replicator"
-u myaccount-dc2
The partition is embedded in the HTTP path when you issue the request to IBM Cloudant:



* Curl
* Java
* Node
* Python
* Go



curl -X POST "$SERVICE_URL/readings/_partition/bridge-9876/_find" -H 'Content-Type:
application/json' --data '{
"selector": {
"ts": { "$gte": "20181213"}
}
}'

import com.ibm.cloud.cloudant.v1.Cloudant;
import com.ibm.cloud.cloudant.v1.model.FindResult;
import com.ibm.cloud.cloudant.v1.model.PostPartitionFindOptions;
import com.ibm.cloud.cloudant.v1.model.Selector;

import java.util.HashMap;
import java.util.Map;

Cloudant service = Cloudant.newInstance();

Map greaterThanOrEqualWithTs = new HashMap<>();
greaterThanOrEqualWithTs.put("$gte", "20181213");

Selector selector = new Selector();
selector.put("ts", greaterThanOrEqualWithTs);

PostPartitionFindOptions findOptions =
new PostPartitionFindOptions.Builder()
.db("readings")
.partitionKey("bridge-9876")
.selector(selector)
.build();

FindResult response =
service.postPartitionFind(findOptions).execute()
.getResult();

System.out.println(response);

import { CloudantV1 } from '@ibm-cloud/cloudant';

const service = CloudantV1.newInstance({});

const selector: CloudantV1.Selector = {
ts: {'$gte': '20181213'}
}
service.postPartitionFind({
buildpack: swift_buildpack

In this manifest.yml file, random-route: true generates a random route for your app to prevent your route from colliding with others. If you choose to, you can replace random-route: true with host: <myChosenHostName>, supplying a host name of your choice.





 Step 4: Deploy the app 

You can use the IBM Cloud® CLI to deploy apps.



1. Log in to your IBM Cloud account, and select an API endpoint.

ibmcloud login

If you have a federated user ID, instead use the following command to log in with your single sign-on ID. See [Logging in with a federated ID](https://cloud.ibm.com/docs/account?topic=account-federated_id) for more information.

ibmcloud login --sso
2. Target a Cloud Foundry org and space:

ibmcloud target --cf

If you don't have an org or a space set up, see [Adding orgs and spaces](https://cloud.ibm.com/docs/account?topic=account-orgsspacesusers).
3. From within the get-started-swift directory, push your app to IBM Cloud

ibmcloud cf push

This can take a minute. If there is an error in the deployment process you can use the command ibmcloud cf logs <Your-App-Name> --recent to troubleshoot.



When deployment completes you should see a message indicating that your app is running. View your app at the URL listed in the output of the push command. You can also issue the following command to view your apps status and see the URL.

ibmcloud cf apps

You can also go to the IBM Cloud [resource list](https://cloud.ibm.com/resources) to view your app.





 Step 5: Add a database 

Next, we'll add an IBM Cloudant NoSQL database to this app and set up the app so that it can run locally and on IBM Cloud.



1. In your browser, log in to IBM Cloud and go to the Dashboard.