Article
· May 4, 2024 3m read

Using VECTORs in ObjectScript

Most examples I've seen so far in OEX or DC left the impression that VECTORs
are just something available with SQL with the 3 Functions especially around VECTOR_Search.
* TO_VECTOR()
* VECTOR_DOT_PRODUCT ()
* VECTOR_COSINE ()

There is a very useful summary hidden in iris-vector-search demo package.
From there you find everything you need over several links and corners.

I was missing more VECTOR methods and placed a related request in Idea Portal

Next I remembered that every SQL Method  or procedure lives on a bunch of ObjectScript code
So I went to search for it an this is the summary of the research.

%Library.Vector is the core description of the new DataType
It's a complex structure like Objects or %DynamicObjects or $Bit Expressions that require specific access methods
We also see 2 required parameters: 
* DATATTYPE  - once set can't be changed.
  Accepted types:  "integer" (or "int"), "double", "decimal", "string", and "timestamp".
* LEN  >0 , may grow bur never shrink

$vector() / $ve()  is the basic method for Vector access
Assign Vector Data  >>>  SET $VE(. . .) = val
Return Vector Data  >>>  WRITE $VE(. . .) ,  SET var=$VE(. . .) 
  HINT: a single position returns the value, but position from::to returns another Vector !
Delete Vector Data  >>>  KILL $VE(. . .) 
All 3 require at least 1 Position parameter. You may understand this as dimensions.

$isvector() the obvious check for correct format before jumping into operations. 

$vectorop() / $vop() covers all other functions related to vectors
The call parameters are typically (operation, vector)
Some operations offer an optional bitexpr. It marks positions/dimensions to be ex-/in-cluded.
Example: 
- Think of a 3D vector. you just want to operate on x - and y axis and not to z 

Single Vector Operations

Aggregate Operations
 * "count"
 * "max"
 * "min"
 * "sum"
Filter Operations
 * "defined"
 * "undefined"
 * "<"
 * "<="
 * ">"
 * ">="
 * "="
 * "!="
 * "between"
Numeric Operations
 * "+"
 * "-"
 * "/"
 * "*"
 * "**"
 * "#"
 * "e-"
 * "e/"
 * "ceiling"
 * "floor"
String Operations
 * "_"
 * "e_"
 * "lower"
 * "upper"
 * "substring"
 * "trim"
 * "triml"
 * "trimr"
Grouping Operations
 * "group"
 * "countgb"
Miscellaneous Operations
 * "convert"
 * "length"
 * "mask"
 * "positions"
 * "set"
Informative Operations
 * "bytesize"
 * "type"

Multi Vector Operations  (mostly 2 vectors)

Vector-wise Filter Operations
 * "v<"
 * "v<="
 * "v>"
 * "v>="
 * "v="
 * "v!="
Vector-wise Arithmetic Operations
 * "v+"
 * "v-"
 * "v/"
 * "v*"
 * "v**"
 * "v#"
Vector Concatenation
 * "v_"
Vector Grouping
 * "countg"
 * "maxg"
 * "ming"
 * "sumg"
Vector Merge
 * "vset"

You see there is a rich set of tools already available.
If you study docs in details, the purpose or advantage of the results may
not be evident immediately. 

Though I hope you got an overview of what is available now.

Discussion (1)1
Log in or sign up to continue