// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.23.0
// source: query.sql

package querytest

import (
	"context"

	"github.com/pgvector/pgvector-go"
)

const insertVector = `-- name: InsertVector :exec
INSERT INTO items (embedding) VALUES ($1)
`

func (q *Queries) InsertVector(ctx context.Context, embedding pgvector.Vector) error {
	_, err := q.db.Exec(ctx, insertVector, embedding)
	return err
}

const nearestNeighbor = `-- name: NearestNeighbor :many
SELECT id, embedding
FROM items
ORDER BY embedding <-> $1
LIMIT 5
`

func (q *Queries) NearestNeighbor(ctx context.Context, embedding pgvector.Vector) ([]Item, error) {
	rows, err := q.db.Query(ctx, nearestNeighbor, embedding)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []Item
	for rows.Next() {
		var i Item
		if err := rows.Scan(&i.ID, &i.Embedding); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}
