Prelude
| Key | Value | Extent |
The prelude includes declaration basic types that form are directly storable in Hiperspace, and types that direct support in the base Hiperspace library
Types
| Type░░░░░░ | Notes░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ |
|---|---|
| Int16 | Integers in the range ±32,768 |
| Int32 | Integers in the range ± 2,147,483,648 |
| Int64 | Integers in the range ± 9,223,372,036,854,775,808 |
| Decimal | Up to 28-digit precise real number |
| Double | Double precision floating point number |
| Single | Single precision floating point number |
| Half | Small floating-point number for AI workloads using two bytes of storage |
| String | Text up to 2Gb in size |
| DateTime | Date and Time with millisecond precision |
| Boolean | True or false |
| Guid | Globally unique identifier |
Collections
| Type░░░░░░ | Notes░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ |
|---|---|
| Set<> | Generic collection of unique items |
| List<> | Generic collection of ordered items |
Functions
| Type░░░░░░ | Notes░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ |
|---|---|
| sum | Sum of collection . value “sum(Transactions.Cost)” |
| avg | Average of collection . value “avg(Transactions.Cost)” |
| max | Maximum value of collection . value “max(Transactions.Cost)” |
| min | Minimum value of collection . value “min(Transactions.Cost)” |
| count | Count of values in collection . value “count(Transactions.Cost)” |
| deltasum | Sum of collection . value “sum(Transactions.Cost)” |
| deltaavg | Average of collection . value “avg(Transactions.Cost)” |
| deltamax | Maximum value of collection . value “max(Transactions.Cost)” |
| deltamin | Minimum value of collection . value “min(Transactions.Cost)” |
| deltacount | Count of values in collection . value “count(Transactions.Cost)” |
functions are declared in the prelude and implemented in Hiperspace
%function ( aggregate, sum, Functions.Sum); /* takes an attribute and collection */
%function ( aggregate, avg, Functions.Avg);
%function ( aggregate, max, Functions.Max);
%function ( aggregate, min, Functions.Min);
%function ( aggregate, count, Functions.Count);
%function ( aggregate, deltasum, Functions.DeltaSum); /* sums and subtracts the value */
%function ( aggregate, deltamax, Functions.DeltaMax); /* prior to the DeltaFrom timestamp */
%function ( aggregate, deltamin, Functions.DeltaMin); /* used when opening the subspace */
%function ( aggregate, deltacount, Functions.DeltaCount);
Delta functions
Delta functions work in conjunction with the DeltaFrom parameter when opening a SubSpace and @DeltaIndex property to implement continues aggregation
If an account has transactions
| ░Account░ | Transaction░ | AsAt░░░░ | Value ░ | Payee░ |
|---|---|---|---|---|
| 1 | 001 | 1/7/24 | $100 | Mathew |
| 1 | 002 | 1/7/24 | $100 | Mark |
| 1 | 003 | 1/7/24 | $100 | Luke |
| 1 | 004 | 1/7/24 | $100 | John |
Balance aggregated on 2/7/24 would be $400,
When the transactions were updated on 3/7/24 with
| ░Account░ | Transaction░ | AsAt░░░░ | Value ░ | Payee░ |
|---|---|---|---|---|
| 1 | 005 | 3/7/24 | $200 | Mary |
| 1 | 002 | 3/7/24 | $200 | Mark |
detasum (with DeltaFrom of 2/7/24 when opening SubSpace) would be $300 because transaction 002 is an amendment of an earlier $100 transaction.
When the deltasum total $300 is added to the snapshot balance $400, the total $700 is the same as if all transactions has been aggregated. This is useful when hundreds, thousands, or more transactions are recorded.
Storing the Balance in an Account aspect provides a continuous balance.
| ░Account░ | AsAt░░░░ | Balance ░ |
|---|---|---|
| 1 | 2/7/24 | $400 |
| 1 | 4/7/24 | $700 |
Opening the SubSpace with an AtAt date 2/7/24 will show a Balance of $400 and Balance.GetVersions() will return the balance history.
Graph view
Hiperspace defined the views Node and Edge and every SubSpace includes SetSpace<Node> Nodes and SetSpace<Edge> Edges that enable any domain space to be treated as a graph database.
"node in a graph view of data"
view Node #2
(
SKey : String #1
)
{
TypeName : String #2,
Name : String #3
}
[
From : Edge (From = this),
To : Edge (To = this)
];
"edge between nodes"
view Edge #3
(
From : Node #2,
To : Node #3,
TypeName : String #4
)
{
Name : String #5,
};
Vector Space
Hiperspace defines VectorSpace and VectorNode to support Nearest Neighbor Search of a VectorSpace
VectorSpace
An aspect that provides the current Vector for an Entity / Segment /Aspect
Contains the key of an Element and a Vector collection of either Integers or Floating point numbers for the Element it refers too. Vector uses TensorPrimitives for {Dot, Cosine, Distance} vector search.
As a versioned aspect, history is retained within hiperspace but older versions are efficiently skipped whe searching (unless SubSpace was opened with an AsAt timestamp)
HasVector
This mix-in type allows VectorSearch to be added as entity Location.Airport : HasVectorSpace ...; to an entity / segment / aspect for VectorSpace search
VectorNode
VectorNode is a view for all Elements that provide a VectorSpace for query other than Nearest Neighbor Search.
"Vector data for a graph node"
view VectorNode #4
(
SKey : String #1,
)
{
Vector : Hiperspace.Vector
};
/* Vector based search */
value Hiperspace.Vector;
" Aspect used to search for similar entities"
@VectorSpace, Versioned
aspect Hiperspace.VectorSpace
{
Vector : Hiperspace.Vector #1
};
@Versioned
type HasVectorSpace
[
VectorSpace : Hiperspace.VectorSpace
];
Utility types
Versioned provides a consistent pattern for Versioned Entity / Segment / Aspect that includes the Deleted tombstone value to exclude deleted Elements from the current view.
Opening a SubSpace with the AsAt parameter will show elements that were valid at that time.
CubeKey is the key to a _Fact table for aggregates used with @CubeDimension, @CubeFact and @CubeMeasure properties
/* helper type to add Versioned attribute and Deleted value */
@Versioned type Versioned { "Flag for read horizon filter to hide when true" Deleted = false };
"Key to a cube projection of a collection of facts"
type CubeKey;
/* utility types */
aspect Option<T>
{
A : T #1
};
segment Many<T>
(
A : T #1
);