In this chapter we will try out a few simple python scripts to access the Kendra index. Note that the objective of this chapter is to familiarize the participants with simple Kendra scripts that can come handy when experimenting with Kendra. All the participants should also read and understand the scripts so that they can write similar scripts for their use very easily.
Before we can start working with the python scripts we need to edit them and replace REPLACE-WITH-YOUR-INDEX-ID with the index-id of the Kendra index you created and REPLACE-WITH-DATASOURCE-ROLE-ARN with the ARN of the data source role for the index.
You can do this by browsing to the scripts folder in the left hand pane and editing the scripts files. This will look like the image below
In the Cloud9 terminal start working in the ~/environment/scripts directory where we extracted all the scripts.
Run each of the following, observe the output and understand the workings of the script. Feel free to try a few other experiements as well.
./sort_search_query.py "amazon kendra"
./sort_search_query.py "amazon kendra" DocumentType
./filter_search_query.py "amazon kendra" blogs
In the following command please replace the s3 bucket name with the name of the bucket you have configured as a datasource.
./put-doc.py yosemite.pdf s3://kendra-poc-ds-UNIQUE-SUFFIX/
After the above command check the search console of the Kendra index and issue query for “yosemite” and confirm that you get results from the document that was just ingested. Note the similarities between this script and the lambda we created.
Change the directory to ~/environment
Now we are ready to move to the next chapter.