branch: externals/vecdb commit ee8779b7e2b87a927dbb8360c85b50bab3a8fc26 Author: Andrew Hyatt <ahy...@gmail.com> Commit: Andrew Hyatt <ahy...@gmail.com>
Fixes for upserting without payload fields --- vecdb-psql.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/vecdb-psql.el b/vecdb-psql.el index fe67f76a87..ca7d9961c4 100644 --- a/vecdb-psql.el +++ b/vecdb-psql.el @@ -126,22 +126,24 @@ DBNAME is the database name, which must have been created by the user." "Upsert items into the COLLECTION in the database PROVIDER. All items in DATA-LIST must have the same paylaods." (pg-exec (vecdb-psql-get-connection provider) - (format "INSERT INTO %s (id, vector, %s) VALUES %s + (format "INSERT INTO %s (id, vector%s %s) VALUES %s ON CONFLICT (id) DO UPDATE SET vector = EXCLUDED.vector%s %s;" (vecdb-psql-table-name (vecdb-collection-name collection)) + (if (vecdb-collection-payload-fields collection) ", " "") ;; We assume every vecdb-item has the same payload structure (mapconcat #'identity (vecdb-psql--plist-keys (vecdb-item-payload (car data-list))) ", ") (mapconcat (lambda (item) - (format "(%d, '[%s]'::vector, %s)" + (format "(%d, '[%s]'::vector%s %s)" (vecdb-item-id item) (mapconcat (lambda (v) (format "%s" v)) (vecdb-item-vector item) ", ") + (if (vecdb-collection-payload-fields collection) ", " "") (mapconcat (lambda (key) (format "'%s'" (plist-get (vecdb-item-payload item)