The results can be accessed through the Python dictionary object returned by Hyperspace_client.search(), which has the following entries –
'took_ms' – Specifies the query time in [ms].
'similarity' – Provides the list of results. Each item in results['similarity'] contains the following entries –
'score' (float) – Specifies the matching score for Classic, Vector or Hybrid Search.
'id' (str) – The unique identifier of a document. This is the same id that you assigned to this data when it was uploaded. You can use this identifier to retrieve the document, as described in Get Document.
Here is an example of what results might look like if they were printed on the screen –
Here's another example of printing results, in which the took_ms is also shown –
print(f"Query run time: {results['took_ms']:.2f}ms")print(f'Query run time / candidates+1 = { results["took_ms"] / (results["candidates"] +1):.2f}')print(results['similarity'])print ("=================================================")
System.out.printf("Query run time: %.2fms%n",results.getTookMs());System.out.printf("Query run time / candidates+1 = %.2f%n",results.getTookMs() / (results.getCandidates() +1));System.out.println(results.getSimilarity());System.out.println("=================================================");
console.log(`Query run time: ${results.took_ms.toFixed(2)}ms`);console.log(`Query run time / candidates+1 = ${(results.took_ms / (results.candidates +1)).toFixed(2)}`);console.log(results.similarity);console.log("=================================================");
The following is printed–
Results for collection data-2023-09-06
==================================
Query run time: 2.82ms
Query run time / candidates+1 = 2.82
Use the following to retrieve and print the results of the search.
for i, x inenumerate(results['similarity']): document = hyperspace_client.get_document(collection_name, x['id'])print(i, document)
for (int i =0; i <results.getSimilarity().size(); i++) {SimilarityResult x =results.getSimilarity().get(i);Document document =hyperspaceClient.getDocument(collectionName,x.getId());System.out.println(i +": "+ document); }
collection_name – Specifies the Collection name from which to retrieve the documents.
id - the id of each result that was returned.
Retrieving Query Results With Selected Fields
Provide the key fields =[...] to Hyperspace_client.search() during the query submission to retrieve selected document fields, in addition to the document Id. See example below -
The results object will now include a field named "fields" that contains the user selected fields. Here is an example of what results might look like now if they were printed on the screen –