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

package db

import (
	"context"
)

const addDummyVectorSegment = `-- name: AddDummyVectorSegment :exec
INSERT INTO segments (id, type, scope,collection) VALUES (?,'urn:chroma:segment/vector/hnsw-local-persisted','VECTOR',?)
RETURNING id, type, scope, collection
`

type AddDummyVectorSegmentParams struct {
	ID         string
	Collection string
}

func (q *Queries) AddDummyVectorSegment(ctx context.Context, arg AddDummyVectorSegmentParams) error {
	_, err := q.db.ExecContext(ctx, addDummyVectorSegment, arg.ID, arg.Collection)
	return err
}

const createFTS = `-- name: CreateFTS :exec
CREATE VIRTUAL TABLE IF NOT EXISTS embedding_fulltext_search USING fts5(string_value, tokenize='trigram')
`

func (q *Queries) CreateFTS(ctx context.Context) error {
	_, err := q.db.ExecContext(ctx, createFTS)
	return err
}

const dropFTS = `-- name: DropFTS :exec
DROP TABLE IF EXISTS embedding_fulltext_search
`

func (q *Queries) DropFTS(ctx context.Context) error {
	_, err := q.db.ExecContext(ctx, dropFTS)
	return err
}

const dropFTSConfig = `-- name: DropFTSConfig :exec
DROP TABLE IF EXISTS embedding_fulltext_search_config
`

func (q *Queries) DropFTSConfig(ctx context.Context) error {
	_, err := q.db.ExecContext(ctx, dropFTSConfig)
	return err
}

const dropFTSContent = `-- name: DropFTSContent :exec
DROP TABLE IF EXISTS embedding_fulltext_search_content
`

func (q *Queries) DropFTSContent(ctx context.Context) error {
	_, err := q.db.ExecContext(ctx, dropFTSContent)
	return err
}

const dropFTSData = `-- name: DropFTSData :exec
DROP TABLE IF EXISTS embedding_fulltext_search_data
`

func (q *Queries) DropFTSData(ctx context.Context) error {
	_, err := q.db.ExecContext(ctx, dropFTSData)
	return err
}

const dropFTSDocsize = `-- name: DropFTSDocsize :exec
DROP TABLE IF EXISTS embedding_fulltext_search_docsize
`

func (q *Queries) DropFTSDocsize(ctx context.Context) error {
	_, err := q.db.ExecContext(ctx, dropFTSDocsize)
	return err
}

const dropFTSIdx = `-- name: DropFTSIdx :exec
DROP TABLE IF EXISTS embedding_fulltext_search_idx
`

func (q *Queries) DropFTSIdx(ctx context.Context) error {
	_, err := q.db.ExecContext(ctx, dropFTSIdx)
	return err
}

const getSegments = `-- name: GetSegments :many
SELECT id, type, scope, collection FROM segments WHERE scope = 'VECTOR'
`

func (q *Queries) GetSegments(ctx context.Context) ([]Segment, error) {
	rows, err := q.db.QueryContext(ctx, getSegments)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []Segment
	for rows.Next() {
		var i Segment
		if err := rows.Scan(
			&i.ID,
			&i.Type,
			&i.Scope,
			&i.Collection,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Close(); err != nil {
		return nil, err
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const insertFTS = `-- name: InsertFTS :exec
INSERT INTO embedding_fulltext_search (rowid, string_value) SELECT em.rowid, COALESCE(doc.string_value, '')
FROM embeddings em
LEFT JOIN embedding_metadata doc
  ON em.id = doc.id
  AND doc.key = 'chroma:document'
GROUP BY doc.id
`

func (q *Queries) InsertFTS(ctx context.Context) error {
	_, err := q.db.ExecContext(ctx, insertFTS)
	return err
}
