How to load vector embeddings into Neo4j?

How to load vector embeddings into Neo4j?
This syntax executed in console will just work, 'embedding' property will be Array(384):

CREATE 
 (Product1:Product {id: 10, name: 'Product Name', description: 'Product Description', embedding:[-1.00518711e-01, 7.83732533e-02,  ...  -2.53117532e-02,-2.13430752e-03]});

This one will load 'embedding' as text (not array as needed):

LOAD CSV FROM 'file:///emb.csv' AS line FIELDTERMINATOR ';'
 CREATE (:Product {id: line[0], name: line[0], description: line[1], embedding: line[2]})

If I strip '[' and ']' characters from embedding column (line[2]) in csv and execute it again:

LOAD CSV FROM 'file:///emb.csv' AS line FIELDTERMINATOR ';'
CREATE (:Product {id: line[0], name: line[0], description: line[1], embedding: [line[2]]})

I get... Array(1) - not Array(384)

I can load it as:

LOAD CSV FROM 'file:///emb_result.csv' AS line FIELDTERMINATOR ';'
CREATE (:Product {id: line[0], name: line[0], description: line[1], embedding: split(line[2], ",")})

I get Array(384) but vector search is not working. Probably because values are... text not float(?).

So how to load vector search embeddings in Neo4j?

Try using toFloatList() to convert your string list to a float list.

LOAD CSV FROM 'file:///emb_result.csv' AS line FIELDTERMINATOR ';'
CREATE (:Product {id: line[0], name: line[0], description: line[1], embedding: toFloatList(split(line[2], ","))})

if this does not work, you can convert using list comprehension:

LOAD CSV FROM 'file:///emb_result.csv' AS line FIELDTERMINATOR ';'
CREATE (:Product {id: line[0], name: line[0], description: line[1], embedding: [x in split(line[2], ",") | toFloat(x)]})
1 Like

Thank you very much indeed for your support!
The first one works just great.