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
  1. flows
  2. Setting Up

Creating a Collection

PreviousIndex Type MethodsNextUploading Data to a Collection

Last updated 10 months ago

The Hyperspace database stores data within Collections, which are distinct segments within the database.

Hyperspace collections act like data containers, housing a large amount of data to be stored together and then accessed.

To enable the usage of the commands described below, you must first create a local Hyperspace instance to ensure the availability of necessary resources and functionalities.

Copy the following code snippet to create a collection –

collection_name = "new_collection"
hyperspace_client.create_collection('schema.json', collection_name)
String collectionName = "new_collection";
JsonObject schema = (JsonObject) 
JsonParser.parseReader(new FileReader("schema.json"));
client.createCollection(collectionName, schema);
const collection_name = 'new_collection';
await hyperspaceClient.indices.create({
    index: collectionName,
    body: 'schema.json'
})

Where –

  • 'schema.json' – Specifies the path to the configuration file (for example, '\schema.json') that you created locally on your machine, as described in

  • collection_name – Specifies the name of the collection to be created in the Hyperspace database. You can specify any name as long as it is unique to your Hyperspace Collection.

Response

The following response should be received –

{'status': 'OK', 'code': 200, 'message': 'Collection was successfully created'}

Alternatively, you can also define the config schema as a python dictionary .

Example -

config_schema = {
  "configuration": {
    "budget": {
      "type": "integer"
    },
    "genres": {
      "struct_type": "list",
      "type": "keyword"
    },
    "id": {
      "type": "keyword",
      "id": True
    },   
    "popularity": {
      "type": "float"
    },
    "rating": {
      "type": "float"
    },
    "release_date_unix_time": {
      "type": "date"
    },  
     "embedded_overview": {
            "type": "dense_vector",
            "dim": 384,
            "index_type": "brute_force",
            "metric": "IP"
      }
  }
}

collection_name = 'new_collrction"

hyperspace_client.create_collection(config_schema, collection_name)

String configSchema = "{"
                       " \"configuration\": {" + 
                       "   \"budget\": {" +
                       "      \"type\": \"integer\"" +
                       "    }," +
                       "     \"genres\": {" +
                       "       \"struct_type\": \"list\"," +
                       "       \"type\": \"keyword\"" +
                       "     }," +
                       "     \"id\": {" +
                       "       \"type\": \"keyword\"," +
                       "       \"id\": True" +
                       "     },   " +
                       "     \"popularity\": {" +
                       "       \"type\": \"float\"" +
                       "     }," +
                       "     \"rating\": {" +
                       "       \"type\": \"float\"" +
                       "     }," +
                       "     \"release_date_unix_time\": {" +
                       "       \"type\": \"date\"" +
                       "     },  " +
                       "      \"embedded_overview\": {" +
                       "             \"type\": \"dense_vector\"," +
                       "             \"dim\": 384," +
                       "             \"index_type\": \"brute_force\"," +
                       "             \"metric\": \"IP\"" +
                       "       }" +
                       "   }" +
                       " }";
hyperspaceClient.createCollection(collectionName, schema);
const configSchema = {
  "configuration": {
    "budget": {
      "type": "integer"
    },
    "genres": {
      "struct_type": "list",
      "type": "keyword"
    },
    "id": {
      "type": "keyword",
      "id": true
    },   
    "popularity": {
      "type": "float"
    },
    "rating": {
      "type": "float"
    },
    "release_date_unix_time": {
      "type": "date"
    },  
     "embedded_overview": {
            "type": "dense_vector",
            "dim": 384,
            "index_type": "brute_force",
            "metric": "IP"
      }
  }
};

const collectionName = "new_collection";

hyperspace_client.createCollection(configSchema, collectionName );

Collections (sometimes referred to as "indexes") are a fundamental concept in databases that may organize data as Collections of documents. Collection's documents have a general predefined structure, but each document within a Collection can have its own unique set of fields and data out of the schema. Serving as containers for related documents and records, Collections facilitate logical grouping, making it simpler to organize, manage, and efficiently query, index, and retrieve related data.

Creating a Database Schema Configuration File.