REGULAR_COLLECTION_NAME = os.getenv('DISCOVERY_REGULAR_COLLECTION_NAME',
                                    'knowledge_base_regular')
ENRICHED_COLLECTION_NAME = os.getenv('DISCOVERY_ENRICHED_COLLECTION_NAME',
                                     'knowledge_base_enriched')

# please provide the collection desired
DESIRED_COLLECTION_NAME = REGULAR_COLLECTION_NAME

# retrieve the following:
# {
#   environment_id,
#   collection_id_regular,
#   collection_id_enriched
# }
discovery_constants = get_constants(discovery,
                                    regular_name=REGULAR_COLLECTION_NAME,
                                    enriched_name=ENRICHED_COLLECTION_NAME)
COLLECTION_ID = discovery_constants['collection_id_regular']
if DESIRED_COLLECTION_NAME == ENRICHED_COLLECTION_NAME:
    COLLECTION_ID = discovery_constants['collection_id_enriched']

qopts = {'natural_language_query': QUESTION, 'count': MAX_DOCUMENTS}

# Invoke search using Discovery query API
output = discovery.query(environment_id=discovery_constants['environment_id'],
                         collection_id=COLLECTION_ID,
                         query_options=qopts)
try:
    print("No. of rows : %d" % output.get('matching_results'))
    print("Results : %s" % json.dumps(output['results'], indent=4))
except:
Пример #2
0
                file_object.seek(0)
                docs_uploaded += 1
                done_percent = write_progress(docs_uploaded, total_documents,
                                              done_percent)

    logging.info("Finished uploading %d files", total_files)
    print("\nFinished uploading %d files" % total_files)


print('Retrieving environment and collection constants...')
"""
retrieve the following:
{
  environment_id: env_id,
  collection_id: {
    regular: regular_id,
    trained: trained_id
  }
}
"""
discovery_constants = get_constants(
    discovery,
    regular_name=os.getenv('DISCOVERY_REGULAR_COLLECTION_NAME',
                           'knowledge_base_regular'),
    trained_name=os.getenv('DISCOVERY_TRAINED_COLLECTION_NAME',
                           'knowledge_base_trained'))
print('Constants retrieved!')
print(discovery_constants)
print("Log file located at: %s" % LOG_FILE_PATH)
upload_documents(DOCS_DIRECTORY)
                             file_object.name, collection_id)
                upload_document(file_object,
                                discovery_constants['environment_id'],
                                collection_id)
                file_object.seek(0)
                docs_uploaded += 1
                done_percent = write_progress(docs_uploaded, total_documents,
                                              done_percent)

    logging.info("Finished uploading %d files", total_files)
    print("\nFinished uploading %d files" % total_files)


print('Retrieving environment and collection constants...')
# retrieve the following:
# {
#   environment_id,
#   collection_id_regular,
#   collection_id_enriched
# }
discovery_constants = get_constants(
    discovery,
    regular_name=os.getenv('DISCOVERY_REGULAR_COLLECTION_NAME',
                           'knowledge_base_regular'),
    enriched_name=os.getenv('DISCOVERY_ENRICHED_COLLECTION_NAME',
                            'knowledge_base_enriched'))
print('Constants retrieved!')
print(discovery_constants)
print("Log file located at: %s" % LOG_FILE_PATH)
upload_documents(DOCS_DIRECTORY)
# please provide the collection desired
DESIRED_COLLECTION_NAME = REGULAR_COLLECTION_NAME

"""
retrieve the following:
{
  environment_id: env_id,
  collection_id: {
    regular: regular_id,
    trained: trained_id
  }
}
"""
discovery_constants = get_constants(
                        discovery,
                        regular_name=REGULAR_COLLECTION_NAME,
                        trained_name=TRAINED_COLLECTION_NAME,
                      )
COLLECTION_ID = discovery_constants['collection_id']['regular']
if DESIRED_COLLECTION_NAME == TRAINED_COLLECTION_NAME:
    COLLECTION_ID = discovery_constants['collection_id']['trained']

qopts = {'natural_language_query': QUESTION, 'count': MAX_DOCUMENTS}

# Invoke search using Discovery query API
output = discovery.query(environment_id=discovery_constants['environment_id'],
                         collection_id=COLLECTION_ID,
                         query_options=qopts)
try:
    print ("No. of rows : %d" % output.get('matching_results'))
    print ("Results : %s" % json.dumps(output['results'], indent=4))