Skip to content

Support vector value type - #456

Open
lolski wants to merge 7 commits into
vector-search-feature-branchfrom
vector-search
Open

Support vector value type#456
lolski wants to merge 7 commits into
vector-search-feature-branchfrom
vector-search

Conversation

@lolski

@lolski lolski commented Jul 10, 2026

Copy link
Copy Markdown
Member

Product change and motivation

Adds support for declaring vector. This lets users work with embeddings, and later express vector-similarity queries.

  1. Declaring a vector embedding attribute
define
attribute embedding,
    value vector(64, "float32");
  1. Inserting a vector embedding attribute: using declarative syntax
insert
$x isa document,
    has embedding vector([1.0, 2.0, 3.0], "float32");
  1. Inserting a vector embedding attribute: using given syntax
given $e: vector(64, "float8");
insert
$x isa document,
    has embedding $e;

Implementation

  • Updated Pest grammar to allow array declarations
  • AST & parser: BuiltinValueTypeArray struct and visitors
  • Updated tests: declaring double array, inserting an array, and calling a function using an array

@lolski lolski changed the title Vector search Support array declarations Jul 10, 2026
@lolski
lolski requested a review from dmitrii-ubskii July 10, 2026 16:48
@lolski
lolski marked this pull request as ready for review July 10, 2026 16:48
@lolski
lolski requested a review from flyingsilverfin as a code owner July 10, 2026 16:48
@lolski
lolski changed the base branch from master to vector-search-feature-branch July 13, 2026 14:35
@lolski lolski changed the title Support array declarations Support vector value type Jul 20, 2026
@lolski
lolski force-pushed the vector-search branch 4 times, most recently from abd2cb6 to 64ce513 Compare July 22, 2026 16:21
Comment thread rust/parser/typeql.pest
expression_struct = { CURLY_OPEN ~ struct_key ~ COLON ~ struct_value ~ CURLY_CLOSE }
struct_value = { expression_value | expression_struct }

vector_literal = { VECTOR ~ PAREN_OPEN ~ expression_list ~ COMMA ~ vector_precision ~ PAREN_CLOSE }

@krishnangovindraj krishnangovindraj Aug 10, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not function, why function shaped :(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@krishnangovindraj rust has the same:

// 1. Definition
struct Color(i32, i32, i32);
struct Point(f64, f64);

@lolski lolski Aug 10, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as a reader i don't find it confusing as it's easy to differentiate them based on the context. in schema declaration where a type is expected, seeing vector(64, "float32") immediately tells me that 64 and "float32" is a type parameter of vector rather than arguments to a function in a function call.

@krishnangovindraj krishnangovindraj Aug 11, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this is the context for an expression rather than a type-declaration. It's not crazy to overload syntax, but this looks like it is just a built-in function named vector? And maybe it should be, because:

  • It's not grouped with the other value_literals, so it presumably can't be used in contexts where they can.
  • The first argument is an expression_list, so it's going to be sent to the ExpressionExecutor all the time anyway.
  • It's technically not a "literal" if it has to be evaluated.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A side effect of this is that nonsense like vector([2024-12-12], "supercalifragilisticexpialidocious"); is not rejected by this grammar. It will fail to parse as a vector_literal, fall back to an expression_function, and the user gets an error saying Could not resolve function with name 'vector'. instead of a more useful error message like Built-in function 'vector' cannot be applied to ....

If the vector literal constructor is function-like, I don't think it belongs in the grammar.

Comment thread rust/parser/expression.rs
let span = node.span();
let mut children = node.into_children();
children.skip_expected(Rule::VECTOR);
let list = visit_expression_list(children.consume_expected(Rule::expression_list));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will return a vector of expressions to the server yes? Do you want to do the validation there? I don't see any we wouldn't allow it, but just to be certain - you'll allow things like vector([1+1, 5.0], "float32") yes?

Comment thread rust/parser/typeql.pest
value_type_optional = { value_type ~ QUESTION }
value_type_list = { value_type ~ SQ_BRACKET_OPEN ~ SQ_BRACKET_CLOSE }
value_type_vector = { VECTOR ~ PAREN_OPEN ~ integer_literal ~ COMMA ~ vector_precision ~ PAREN_CLOSE }
vector_precision = @{ "\"" ~ "float32" ~ "\"" }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"float32" (etc. down the line) should be separate rules in the pest grammar, and vector_precision should be compound atomic ${ }.
We already have the parser, we shouldn't need to trim its outputs.

Comment thread rust/parser/typeql.pest
expression_struct = { CURLY_OPEN ~ struct_key ~ COLON ~ struct_value ~ CURLY_CLOSE }
struct_value = { expression_value | expression_struct }

vector_literal = { VECTOR ~ PAREN_OPEN ~ expression_list ~ COMMA ~ vector_precision ~ PAREN_CLOSE }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A side effect of this is that nonsense like vector([2024-12-12], "supercalifragilisticexpialidocious"); is not rejected by this grammar. It will fail to parse as a vector_literal, fall back to an expression_function, and the user gets an error saying Could not resolve function with name 'vector'. instead of a more useful error message like Built-in function 'vector' cannot be applied to ....

If the vector literal constructor is function-like, I don't think it belongs in the grammar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants