Hyperspace Docs
Hyperspace Homepage
  • Getting started
    • Overview
      • Hyperspace Advantages
      • Hyperspace Search
    • Quick Start
  • flows
    • Setting Up
      • Installing the Hyperspace API Client
      • Connecting to the Hyperspace Server
      • Creating a Database Schema Configuration File
        • Vector Similarity Metrics
        • Index Type Methods
      • Creating a Collection
      • Uploading Data to a Collection
      • Building and Running Queries
        • Building a Lexical Search Query
        • Building a Vector Search Query
        • Building a Hybrid Search Query
      • Retrieving Results
    • Data Collections
      • Uploading Data
      • Accessing Data
      • Supported Data Types
    • Queries
      • DSL Query interface
        • Aggregations
        • Bool Query
        • Candidate Generation and Metadata Filtering
        • Scoring and Ranking
  • Reference
    • Hyperspace Query Flow
    • Features and Benefits
    • Search Processing Unit (SPU)
    • Hyperspace Document Prototype
  • API Documentation
    • Hyperspace Client
      • add_batch
      • add_document
      • async_req
      • clear_collection
      • collections_info
      • commit
      • create_collection
      • delete_collection
      • delete_by_query
      • dsl_search
      • get_schema
      • get_document
      • reset_password
      • search
      • update_by_query
      • update_document
    • DSL Query Framework
      • Aggregations
        • Cardinality Aggregation
        • Date Histogram
        • Metric Aggregations
        • Terms Aggregation
      • Bool Queries
        • Free Text Search
        • 'match' Clause
        • 'filter' Clause
        • 'must' Clause
        • 'must_not' Clause
        • 'should' Clause
        • 'should_not' Clause
      • Candidate Generation and Metadata Filtering
        • Geo Coordinates Match
        • Range Match
        • Term Match
      • Scoring and Ranking
        • Boost
        • 'dis_max'
        • Function Score
        • Rarity Score (TF-IDF)
  • Releases
    • 2024 Releases
Powered by GitBook
On this page
  • Retrieving Query Results By Id
  • Retrieving Query Results With Selected Fields
  1. flows
  2. Setting Up

Retrieving Results

PreviousBuilding a Hybrid Search QueryNextData Collections

Last updated 11 months ago

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 .

Here is an example of what results might look like if they were printed on the screen –

results = Hyperspace_client.search(({"params": data_point,
                                     "query": {query_string}
                                     },
                                     size=5,              
                                     collection_name=collection_name)
print(results)['similarity']) 
Object results = HyperspaceClient.search(query,
                                        size=5,              
                                        collection_name=collection_name);
JsonObject queryResponse = new Gson().toJsonTree(response).getAsJsonObject();
System.out.println(queryResponse);
const results = HyperspaceClient.search(query,
                                        size=5,              
                                        collection_name=collection_name);
console.log(results.similarity);

[{'score: 513.7000122070312, 'id': '78254'}, {'score: 512.5500126784442, 'id': '23091'}, {'score: 485.5471220787652, 'id': '85432'}]

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

[{'score: 513.7000122070312, 'id': '78254'}, {'score: 512.5500126784442, 'id': '23091'}, {'score: 485.5471220787652, 'id': '85432'}]

Retrieving Query Results By Id

Use the following to retrieve and print the results of the search.

for i, x in enumerate(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);
        }
results.similarity.forEach((x, i) => {
    let document = hyperspaceClient.getDocument(collection_name, x.id);
    console.log(i, document);
});

Where –

  • 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 -

results = hyperspace_client.search(query_schema, 
                                size=1,
                                collection_name=collection_name,
                                function_name="score_function",
                                fields=["FirstSeenTime", "City"])
print(results)
Object results = hyperspaceClient.search(query_schema, 
                                size=1,
                                collection_name=collection_name,
                                function_name="score_function",
                                fields=["FirstSeenTime", "City"]);
console.log(results);
const results = hyperspaceClient.search(query_schema, 
                                size=1,
                                collection_name=collection_name,
                                function_name="score_function",
                                fields=["FirstSeenTime", "City"]);
console.log(results);

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 –

{ "candidates": 1, "similarity": [ { "document_id": "29", "score": 10.0, "fields": { "FirstSeenTime": 1506116398, "City": "Jakarta" } } ], "took_ms": 33.625 }

Get Document