Skip to content

Conversation

@StephenCathcart
Copy link
Contributor

@StephenCathcart StephenCathcart commented Nov 24, 2025

Closes DRIVERS-115

  • Vector is now a struct that holds a slice of elements.
  • Tightened constraint on VectorElement.
  • Added Vector type variants to RecordValue and PropertyValue interfaces, enabling extraction via GetRecordValue and GetProperty.
  • Aliases are working as intended. User-defined types are unsupported (similar to other dbtype structures).
vec := neo4j.Vector[float64]{Elems: []float64{1.0, 2.0, 3.0}}

// Create a node with a vector property
result, err := neo4j.ExecuteQuery(ctx, driver,
	"CREATE (n:VectorExample {vec: $vec}) RETURN n, n.vec AS vec",
	map[string]any{"vec": vec},
	neo4j.EagerResultTransformer)

record := result.Records[0]

// Use GetRecordValue to extract vector from record
recordVec, _, err := neo4j.GetRecordValue[neo4j.Vector[float64]](record, "vec")

// Use GetProperty to extract vector from node
node := record.Values[0].(neo4j.Node)
propVec, err := neo4j.GetProperty[neo4j.Vector[float64]](node, "vec")

@StephenCathcart StephenCathcart marked this pull request as ready for review November 24, 2025 15:40
@robsdedude robsdedude self-requested a review December 2, 2025 13:14
[]byte | []any | map[string]any |
Node | Relationship | Path
Node | Relationship | Path |
Vector[int8] | Vector[int16] | Vector[int32] | Vector[int64] | Vector[float32] | Vector[float64]
Copy link
Member

Choose a reason for hiding this comment

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

Nit: could expand GetRecordValue tests to cover new types.

Comment on lines +32 to +37
var _ Vector[float64]
var _ Vector[float32]
var _ Vector[int8]
var _ Vector[int16]
var _ Vector[int32]
var _ Vector[int64]
Copy link
Member

Choose a reason for hiding this comment

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

nit: might want to add dbtype aliases

{"empty int64", Vector[int64]{}, "vector([], 0, INTEGER NOT NULL)"},
{"empty float32", Vector[float32]{}, "vector([], 0, FLOAT32 NOT NULL)"},
{"empty float64", Vector[float64]{}, "vector([], 0, FLOAT NOT NULL)"},
{"empty int8", Vector[int8]{Elems: []int8{}}, "vector([], 0, INTEGER8 NOT NULL)"},
Copy link
Member

Choose a reason for hiding this comment

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

While looking at this, I'm ever so slightly annoyed by having to read (and potentially having to write) the inner vector type twice...

I mean users can avoid this by writing a simple

func makeVec[T dbtype.VectorElement](elems []T) neo4j.Vector[T] {
	return neo4j.Vector[T]{Elems: elems}
}

or similar... As a more seasoned Go dev, what's your gut feeling? Is it worth adding such a helper function to the driver or is it unnecessary noise?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants