vania-janet/multiturn-rag-retrieval-data huggingface dataset:
Get single property 

import { useProperty } from 'ibm-appconfiguration-react-client-sdk';

const property = useProperty('check-in-charges');

if(property) {
console.log(Property Name ${property.getPropertyName()});
console.log(Property Id ${property.getPropertyId()});
console.log(Property Type ${property.getPropertyDataType()});
}





 Get all properties 

import { useProperties } from 'ibm-appconfiguration-react-client-sdk';

const properties = useProperties();

const property = properties["property_id"];

if(property) {
console.log(Property Name ${property.getPropertyName()});
console.log(Property Id ${property.getPropertyId()});
console.log(Property Type ${property.getPropertyDataType()});
}





 Evaluate a property 

Use the property.getCurrentValue(entityId, entityAttributes) method to evaluate the value of the property. This method returns the default property value or its overridden value based on the evaluation. The data type of returned value matches that of property.

const entityId = 'john_doe';
const entityAttributes = {
city: 'Bangalore',
country: 'India',
};

const propertyValue = property.getCurrentValue(entityId, entityAttributes);

Where:



* entityId: Id of the Entity. This will be a string identifier related to the Entity against which the property is evaluated. For any entity to interact with App Configuration, it must provide a unique entity ID.
* entityAttributes: A JSON object consisting of the attribute name and their values that defines the specified entity. This is an optional parameter if the property is not configured with any targeting definition.
s3Client.getObject( // write the contents of the object
request, // using the request that was just created
new File("retrieved.txt") // to write to a new file
);





 Download object by using a stream 

This example assumes that the bucket sample exists.

S3Object returned = cos.getObject( // request the object by identifying
"sample", // the name of the bucket
"serialized-object" // the name of the serialized object
);
S3ObjectInputStream s3Input = returned.getObjectContent(); // set the object stream





 Copy objects 

// copy an object within the same Bucket
cos.copyObject( // copy the Object, passing…
"sample", // the name of the Bucket in which the Object to be copied is stored,
"myFile.txt", // the name of the Object being copied from the source Bucket,
"sample", // the name of the Bucket in which the Object to be copied is stored,
"myFile.txt.backup" // and the new name of the copy of the Object to be copied
);

// copy an object between two Buckets
cos.copyObject( // copy the Object, passing…
"sample", // the name of the Bucket from which the Object will be copied,
"myFile.txt", // the name of the Object being copied from the source Bucket,
"backup", // the name of the Bucket to which the Object will be copied,
"myFile.txt" // and the name of the copied Object in the destination Bucket
);

SDK References



* Classes



* [ObjectMetadata](https://ibm.github.io/ibm-cos-sdk-java/com/ibm/cloud/objectstorage/services/s3/model/ObjectMetadata.html)
![Shows responses that are returned to answer the question about muni bonds.](https://cloud.ibm.com/docs-content/v1/content/f16b1f78a92498247223b337bd9303c2758b9ba8/discovery-data/images/tut-sdu-muni-responses.png)

Figure 28. Responses that answer the question about muni bonds

Click the View passage in document link to see the full definition highlighted in the document.

Transactions in municipal bonds must be reported to the Municipal Securities Rulemaking Board’s (MSRB) Real-time Transaction Reporting System (RTRS).



Congratulations! You successfully added a user-trained Smart Document Understanding (SDU) model that improves the quality of your search project.





 Step 9: Filter results with a dictionary-based facet 

Now that we are getting more passages returned per query, it might be useful to filter the results. To filter the results based on the types of financial instruments that are mentioned, we can add a search facet. One available source for a facet is a dictionary.



1. To create a dictionary, from the Improvement tools panel of the Improve and customize page, expand Teach domain concepts, and then click Dictionaries.

Zoom

![Shows the Dictionaries option from the Teach domain concepts tool panel.](https://cloud.ibm.com/docs-content/v1/content/f16b1f78a92498247223b337bd9303c2758b9ba8/discovery-data/images/tut-sdu-dictionary.png)

Figure 29. Dictionaries tool
2. Click New.

Zoom

![Shows the New button in the dictionary page.]
* [deleteBucket](https://ibm.github.io/ibm-cos-sdk-js/AWS/S3.htmldeleteBucket-property)







 Execute a multi-part upload 

function multiPartUpload(bucketName, itemName, filePath) {
var uploadID = null;

if (!fs.existsSync(filePath)) {
log.error(new Error(The file '${filePath}' does not exist or is not accessible.));
return;
}

console.log(Starting multi-part upload for ${itemName} to bucket: ${bucketName});
return cos.createMultipartUpload({
Bucket: bucketName,
Key: itemName
}).promise()
.then((data) => {
uploadID = data.UploadId;

//begin the file upload
fs.readFile(filePath, (e, fileData) => {
//min 5MB part
var partSize = 1024 * 1024 * 5;
var partCount = Math.ceil(fileData.length / partSize);

async.timesSeries(partCount, (partNum, next) => {
var start = partNum * partSize;
var end = Math.min(start + partSize, fileData.length);

partNum++;

console.log(Uploading to ${itemName} (part ${partNum} of ${partCount}));

cos.uploadPart({
Body: fileData.slice(start, end),
Bucket: bucketName,
Key: itemName,
PartNumber: partNum,
UploadId: uploadID
}).promise()
.then((data) => {
next(e, {ETag: data.ETag, PartNumber: partNum});
})
.catch((e) => {
Where:



* entityId: Id of the Entity. This will be a string identifier related to the Entity against which the property is evaluated. For any entity to interact with App Configuration, it must provide a unique entity ID.
* entityAttributes: A JSON object consisting of the attribute name and their values that defines the specified entity. This is an optional parameter if the property is not configured with any targeting definition. If the targeting is configured, then entityAttributes should be provided for the rule evaluation. An attribute is a parameter that is used to define a segment. The SDK uses the attribute values to determine if the specified entity satisfies the targeting rules, and returns the appropriate property value.











 Supported data types 

You can configure feature flags and properties with App Configuration, supporting the following data types: Boolean, Numeric, and String. The String data type can be in the format of a text string, JSON, or YAML. The SDK processes each format as shown in the table.



Table 1. Example outputs

 Feature or Property value Data type Data format Type of data returned by getCurrentValue() Example output 

 true BOOLEAN not applicable boolean true 
 25 NUMERIC not applicable number 25 
 a string text STRING TEXT string a string text 
 {"firefox": { <br>"name": "Firefox", <br>"pref_url": "about:config" <br>}} STRING JSON org.json.JSONObject {"firefox":{"name":"Firefox","pref_url":"about:config"}} 
 men: <br>- John Smith <br>- Bill Jones <br>women: <br>- Mary Smith <br>- Susan Williams STRING YAML java.lang.String `"men:<br><br><br><br> * John Smith<br> * Bill Jones\women:<br> * Mary Smith<br> * Susan Williams"`<br><br><br> 





 Feature flag usage example
city: 'Bangalore',
country: 'India',
};

const propertyValue = property.getCurrentValue(entityId, entityAttributes);

Where:



* entityId: Id of the Entity. This will be a string identifier related to the Entity against which the property is evaluated. For any entity to interact with App Configuration, it must provide a unique entity ID.
* entityAttributes: A JSON object consisting of the attribute name and their values that defines the specified entity. This is an optional parameter if the property is not configured with any targeting definition. If the targeting is configured, then entityAttributes should be provided for the rule evaluation. An attribute is a parameter that is used to define a segment. The SDK uses the attribute values to determine if the specified entity satisfies the targeting rules, and returns the appropriate property value.











 Supported data types 

You can configure feature flags and properties with App Configuration, supporting the following data types: Boolean, Numeric, and String. The String data type can be in the format of a text string, JSON, or YAML. The SDK processes each format as shown in the table.



Table 1. Example outputs

 Feature or Property value Data type Data format Type of data returned by getCurrentValue() Example output 

 true BOOLEAN not applicable boolean true 
 25 NUMERIC not applicable number 25 
 a string text STRING TEXT string a string text 
 {"firefox": { <br>"name": "Firefox", <br>"pref_url": "about:config" <br>}} STRING JSON org.json.JSONObject {"firefox":{"name":"Firefox","pref_url":"about:config"}}
delete_item(new_bucket_name, new_text_file_name)

 remove the new bucket
delete_bucket(new_bucket_name)
except Exception as e:
log_error("Main Program Error: {0}".format(e))

if __name__ == "__main__":
main()

package main
import (
"bytes"
"fmt"
"github.com/IBM/ibm-cos-sdk-go/aws"
"github.com/IBM/ibm-cos-sdk-go/aws/credentials/ibmiam"
"github.com/IBM/ibm-cos-sdk-go/aws/session"
"github.com/IBM/ibm-cos-sdk-go/service/s3"
"io"
"math/rand"
"os"
"time"
)

// Constants for IBM COS values
const (
apiKey = "<api-key>" // example: xxxd12V2QHXbjaM99G9tWyYDgF_0gYdlQ8aWALIQxXx4
serviceInstanceID = "<resource-instance-id>" // example: crn:v1:bluemix:public:cloud-object-storage:global:a/xx999cd94a0dda86fd8eff3191349999:9999b05b-x999-4917-xxxx-9d5b326a1111::
authEndpoint = "https://iam.cloud.ibm.com/identity/token"
serviceEndpoint = "<endpoint>" // example: https://s3.us-south.cloud-object-storage.appdomain.cloud
)

// UUID
func random(min int, max int) int {
return rand.Intn(max-min) + min
}

func main() {
* Node



curl -v -X POST -k --header 'Content-Type: application/json'
--header 'Accept: application/json'
--header 'Authorization: bearer <your IAM token>'
-d '{"query": "name:myresource"}' 'https://api.global-search-tagging.cloud.ibm.com/v3/resources/search'

SearchOptions searchOptions = new SearchOptions.Builder()
.query("GST-sdk-")
.fields(new java.util.ArrayList<String>(java.util.Arrays.asList("crn")))
.searchCursor(searchCursor)
.build();

Response<ScanResult> response = service.search(searchOptions).execute();
ScanResult scanResult = response.getResult();

System.out.println(scanResult);

response = global_search_service.search(query='GST-sdk-',
fields=['crn'])
scan_result = response.get_result()

print(json.dumps(scan_result, indent=2))

searchOptions := globalSearchService.NewSearchOptions()
searchOptions.SetLimit(10)
searchOptions.SetQuery("GST-sdk-")
searchOptions.SetFields([]string{"crn"})

scanResult, response, err := globalSearchService.Search(searchOptions)
if err != nil {
panic(err)
}
b, _ := json.MarshalIndent(scanResult, "", " ")
fmt.Println(string(b))

const params = {
query: 'GST-sdk-',
fields: ['crn'],
searchCursor: searchCursor,
};
{"firefox": { <br>"name": "Firefox", <br>"pref_url": "about:config" <br>}} STRING JSON JSONObject {"firefox":{"name":"Firefox","pref_url":"about:config"}} 
 men: <br>- John Smith <br>- Bill Jones <br>women: <br>- Mary Smith <br>- Susan Williams STRING YAML java.lang.String `"men:<br><br><br><br> * John Smith<br> * Bill Jones\women:<br> * Mary Smith<br> * Susan Williams"`<br><br><br> 



For property of type secret reference, refer to readme section [evaluate a secret property](https://cloud.ibm.com/docs/app-configuration?topic=app-configuration-ac-integrate-sdksac-integrate-node-evaluate-secret-property).



 Feature flag 

const feature = appConfigClient.getFeature('json-feature');
feature.getFeatureDataType(); // STRING
feature.getFeatureDataFormat(); // JSON

// Example (traversing the returned JSON)
let result = feature.getCurrentValue(entityId, entityAttributes);
console.log(result.value.key) // prints the value of the key

const feature = appConfigClient.getFeature('yaml-feature');
feature.getFeatureDataType(); // STRING
feature.getFeatureDataFormat(); // YAML
feature.getCurrentValue(entityId, entityAttributes);





 Property 

const property = appConfigClient.getProperty('json-property');
property.getPropertyDataType(); // STRING
property.getPropertyDataFormat(); // JSON
curl -X POST -H "Authorization: {iam_token}" -H "Accept: application/json" -H "Content-Type: application/json" -d '{"query": "tags:project\:myproject OR access_tags:project\:myproject", "fields": [""]}' "api.global-search-tagging.cloud.ibm.com/v3/resources/search"

SearchOptions searchOptions = new SearchOptions.Builder()
.query("GST-sdk-")
.fields(new java.util.ArrayList<String>(java.util.Arrays.asList("")))
.searchCursor(searchCursor)
.build();

Response<ScanResult> response = service.search(searchOptions).execute();
ScanResult scanResult = response.getResult();

System.out.println(scanResult);

response = global_search_service.search(query='GST-sdk-',
fields=[''])
scan_result = response.get_result()

print(json.dumps(scan_result, indent=2))

searchOptions := globalSearchService.NewSearchOptions()
searchOptions.SetLimit(10)
searchOptions.SetQuery("GST-sdk-")
searchOptions.SetFields([]string{""})

scanResult, response, err := globalSearchService.Search(searchOptions)
if err != nil {
panic(err)
}
b, _ := json.MarshalIndent(scanResult, "", " ")
fmt.Println(string(b))

const params = {
query: 'GST-sdk-',
fields: [''],
searchCursor: searchCursor,
};
public static void getItemACL(String bucketName, String itemName) {
System.out.printf("Retrieving ACL for %s from bucket: %sn", itemName, bucketName);

AccessControlList acl = _cos.getObjectAcl(bucketName, itemName);

List<Grant> grants = acl.getGrantsAsList();

for (Grant grant : grants) {
System.out.printf("User: %s (%s)n", grant.getGrantee().getIdentifier(), grant.getPermission().toString());
}
}

SDK References



* Classes



* [AccessControlList](https://ibm.github.io/ibm-cos-sdk-java/com/ibm/cloud/objectstorage/services/s3/model/AccessControlList.html)
* [Grant](https://ibm.github.io/ibm-cos-sdk-java/com/ibm/cloud/objectstorage/services/s3/model/Grant.html)



* Methods



* [getObjectAcl](https://ibm.github.io/ibm-cos-sdk-java/com/ibm/cloud/objectstorage/services/s3/AmazonS3.htmlgetObjectAcl-java.lang.String-java.lang.String-)









 Execute a multi-part upload 

public static void multiPartUpload(String bucketName, String itemName, String filePath) {
File file = new File(filePath);
if (!file.isFile()) {
System.out.printf("The file '%s' does not exist or is not accessible.n", filePath);
return;
}

System.out.printf("Starting multi-part upload for %s to bucket: %sn", itemName, bucketName);
SDK[Global Search](https://cloud.ibm.com/apidocs/search)Global Search Platform SDK[Global Tagging](https://cloud.ibm.com/apidocs/tagging)Global Tagging Platform SDK[IAM Access Groups](https://cloud.ibm.com/apidocs/iam-access-groups)IAM Access Groups Platform SDK[IAM Identity Services](https://cloud.ibm.com/apidocs/iam-identity-token-api)IAM Identity Services SDK[IAM Policy Management](https://cloud.ibm.com/apidocs/iam-policy-management)IAM Policy Management Platform SDK[IBM Cloud Open Service Broker](https://cloud.ibm.com/apidocs/resource-controller/ibm-cloud-osb-api)IBM Cloud Open Service Broker Platform SDK[IBM Cloud Shell](https://cloud.ibm.com/apidocs/cloudshell)IBM Cloud Shell Platform SDK[Partner Center Sell](https://cloud.ibm.com/apidocs/partner-center-sell)Partner Center Sell Platform[Projects]
11. Enter Where do muni bond trades get reported to? as the search query.

The Dictionary terms facet that you created is displayed along with the search results. A Municipal Bonds checkbox is shown, which indicates that at least one of the returned passages is extracted from a document segment with the term Municipal Bonds in its subtitle field.

Zoom

![Shows the Dictionary terms facet with a Municipal Bonds option.](https://cloud.ibm.com/docs-content/v1/content/f16b1f78a92498247223b337bd9303c2758b9ba8/discovery-data/images/tut-sdu-muni-bonds-facet.png)

Figure 37. Dictionary term facet with a Municipal Bonds option
12. To filter the results to show only passages from sections with Municipal Bonds in the subtitle, select the Municipal Bonds checkbox.

The best answer is now listed as the second response instead of the third.

Zoom

![Best answer now is listed as the second result in the list](https://cloud.ibm.com/docs-content/v1/content/f16b1f78a92498247223b337bd9303c2758b9ba8/discovery-data/images/tut-sdu-muni-selected.png)

Figure 38. Best answer is the second result





 Summary 

In this tutorial, you created a Document Retrieval project, a Smart Document Understanding (SDU) model, a dictionary enrichment, and a search facet. You applied the facet that is based on your dictionary to the custom field that is generated by your SDU model to filter your query results for better answers.
: Returns a short integer value, or the value zero if no match is found, or a match is found but the value is nonnumeric.
: Example of an SQL function usage fragment

> SELECT xpath_short('<a><b>1</b><b>2</b></a>', 'sum(a/b)')
: Result value

3





 xpath_string 

xpath_string(xml, xpath)
: Returns the text contents of the first xml node that matches the XPath expression.
: Example of an SQL function usage fragment

> SELECT xpath_string('<a><b>b</b><c>cc</c></a>','a/c')
: Result value

cc





 year 

year(date)
: Returns the year component of the date/timestamp.
: Example of an SQL function usage fragment

> SELECT year('2016-07-30')
: Result value

2016





 | 

expr1 | expr2
: Returns the result of bitwise OR of expr1 and expr2.
: Example of an SQL function usage fragment

> SELECT 3 | 5;
: Result value

7

## 
: expr
: Returns the result of bitwise NOT of expr.
: Example of an SQL function usage fragment

> SELECT 0;
: Result value

-1
.withEndpointConfiguration(new EndpointConfiguration(endpoint_url, location)).withPathStyleAccessEnabled(true)
.withClientConfiguration(clientConfig).build();
return cosClient;
}
}





 Examine a bucket’s lifecycle configuration, including expiration 

This implementation of the GET operation uses the lifecycle query parameter to examine lifecycle settings for the bucket. An HTTP 404 response will be returned if no lifecycle configuration is present.

Cloud IAM users must have the Reader role to examine a lifecycle policy from a bucket.

Classic Infrastructure Users must have Read permissions on the bucket to examine a lifecycle policy from a bucket.



 Header Type Description 

 Content-MD5 String Required: The base64 encoded 128-bit MD5 hash of the payload, which is used as an integrity check to ensure that the payload wasn't altered in transit. 



Syntax

GET https://{endpoint}/{bucket}?lifecycle path style
GET https://{bucket}.{endpoint}?lifecycle virtual host style

Example Header Request

GET /images?lifecycle HTTP/1.1
Host: s3.us.cloud-object-storage.appdomain.cloud
Date: Wed, 7 Feb 2018 17:50:00 GMT
Authorization: authorization string
Content-Type: text/plain
Content-MD5: M625BaNwd/OytcM7O5gIaQ==
Content-Length: 305

Using the IBM Cloud® Object Storage SDKs only requires calling the appropriate functions with the correct parameters and proper configuration.



* Python
* Node



import sys
import ibm_boto3
from ibm_botocore.client import Config

api_key = "ZRZDoNoUseOLL7bRO8SAMPLEHPUzUL_-fsampleyYE"
service_instance_id = "85SAMPLE-eDOb-4NOT-bUSE-86nnnb31eaxx"
auth_endpoint = "https://iam.cloud.ibm.com/identity/token"
apiKeyId: 'ZRZDoNoUseOLL7bRO8SAMPLEHPUzUL_-fsampleyYE',
ibmAuthEndpoint: 'https://iam.cloud.ibm.com/identity/token',
serviceInstanceId: 'crn:v1:bluemix:public:cloud-object-storage:global:a/<CREDENTIAL_ID_AS_GENERATED>:<SERVICE_ID_AS_GENERATED>::',
};
var s3 = new aws.S3(config);

var params = {
Bucket: 'STRING_VALUE' /* required /
};

s3.deleteBucketLifecycleConfiguration(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});

Using the IBM Cloud® Object Storage SDKs only requires calling the appropriate functions with the correct parameters and proper configuration.

import sys
import ibm_boto3
from ibm_botocore.client import Config

api_key = "ZRZDoNoUseOLL7bRO8SAMPLEHPUzUL_-fsampleyYE"
service_instance_id = "85SAMPLE-eDOb-4NOT-bUSE-86nnnb31eaxx"
auth_endpoint = "https://iam.cloud.ibm.com/identity/token"
service_endpoint = "https://s3.us-south.cloud-object-storage.appdomain.cloud"

cos = ibm_boto3.resource('s3',
ibm_api_key_id=api_key,
ibm_service_instance_id=service_instance_id,
ibm_auth_endpoint=auth_endpoint,
config=Config(signature_version='oauth'),
endpoint_url=service_endpoint)
import com.ibm.cloud.sdk.core.security.;
import java.util.HashMap;

private static IbmAnalyticsEngineApi ibmAnalyticsEngineApiService;

private static String IAM_API_KEY = "{apikey}";
private static String IAE_ENDPOINT_URL = "{url}";
private static String API_AUTH_URL = "{api auth url}";

public static void main(String[] args)
{
HashMap<String, String> config = new HashMap<String, String>();
config.put("APIKEY",IAM_API_KEY );
config.put("AUTH_URL", API_AUTH_URL);

try {
// Create an IAM authenticator.
Authenticator authenticator = IamAuthenticator.fromConfiguration(config);
// Construct the service client.
ibmAnalyticsEngineApiService = new IbmAnalyticsEngineApi(IbmAnalyticsEngineApi.DEFAULT_SERVICE_NAME, authenticator);
// Set our service URL.
ibmAnalyticsEngineApiService.setServiceUrl(IAE_ENDPOINT_URL);
}
catch (Exception e) {
System.out.println("Exception");
}
}
Show more
* By using external configuration properties

To avoid hard-coding sourcing credentials, you can store these values in configuration properties outside of your application.

To use configuration properties:



1. Define the configuration properties to be used by your application. These properties can be implemented as:



* Exported environment variables
* Values stored in a credentials file

The following example shows using environment variables. Each environment variable must be prefixed by IBM_ANALYTICS_ENGINE_API.

export IBM_ANALYTICS_ENGINE_API_URL=<IAE_ENDPOINT_URL>
apiKeyId: 'ZRZDoNoUseOLL7bRO8SAMPLEHPUzUL_-fsampleyYE',
ibmAuthEndpoint: 'https://iam.cloud.ibm.com/identity/token',
serviceInstanceId: 'crn:v1:bluemix:public:cloud-object-storage:global:a/<CREDENTIAL_ID_AS_GENERATED>:<SERVICE_ID_AS_GENERATED>::',
};
var s3 = new aws.S3(config);

var params = {
Bucket: 'STRING_VALUE' /* required /
};

s3.deleteBucketLifecycleConfiguration(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
Show more

Using the IBM Cloud® Object Storage SDKs only requires calling the appropriate functions with the correct parameters and proper configuration.

import sys
import ibm_boto3
from ibm_botocore.client import Config

api_key = "ZRZDoNoUseOLL7bRO8SAMPLEHPUzUL_-fsampleyYE"
service_instance_id = "85SAMPLE-eDOb-4NOT-bUSE-86nnnb31eaxx"
auth_endpoint = "https://iam.cloud.ibm.com/identity/token"
service_endpoint = "https://s3.us-south.cloud-object-storage.appdomain.cloud"

cos = ibm_boto3.resource('s3',
ibm_api_key_id=api_key,
ibm_service_instance_id=service_instance_id,
ibm_auth_endpoint=auth_endpoint,
config=Config(signature_version='oauth'),
endpoint_url=service_endpoint)