175 lines
4.6 KiB
Go
175 lines
4.6 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: recall_decay.sql
|
|
|
|
package sqlc
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/ZanzyTHEbar/dragonscale/pkg/ids"
|
|
"github.com/ZanzyTHEbar/dragonscale/pkg/memory"
|
|
)
|
|
|
|
const CountArchivalChunksWithoutEmbedding = `-- name: CountArchivalChunksWithoutEmbedding :one
|
|
SELECT COUNT(*)
|
|
FROM archival_chunks
|
|
WHERE embedding IS NULL
|
|
AND suppressed_at IS NULL
|
|
`
|
|
|
|
// CountArchivalChunksWithoutEmbedding
|
|
//
|
|
// SELECT COUNT(*)
|
|
// FROM archival_chunks
|
|
// WHERE embedding IS NULL
|
|
// AND suppressed_at IS NULL
|
|
func (q *Queries) CountArchivalChunksWithoutEmbedding(ctx context.Context) (int64, error) {
|
|
row := q.db.QueryRowContext(ctx, CountArchivalChunksWithoutEmbedding)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const DecayRecallImportanceBatch = `-- name: DecayRecallImportanceBatch :exec
|
|
UPDATE recall_items
|
|
SET importance = MAX(
|
|
recall_items.importance * ?1,
|
|
?2
|
|
),
|
|
updated_at = datetime('now')
|
|
WHERE recall_items.id IN (
|
|
SELECT ri.id
|
|
FROM recall_items ri
|
|
WHERE ri.importance > ?2
|
|
AND ri.suppressed_at IS NULL
|
|
ORDER BY ri.updated_at ASC
|
|
LIMIT ?3
|
|
)
|
|
`
|
|
|
|
type DecayRecallImportanceBatchParams struct {
|
|
Factor float64 `db:"factor" json:"factor"`
|
|
FloorVal interface{} `db:"floor_val" json:"floor_val"`
|
|
BatchSize int64 `db:"batch_size" json:"batch_size"`
|
|
}
|
|
|
|
// Batch decay of recall item importance (Cortex decay task)
|
|
//
|
|
// UPDATE recall_items
|
|
// SET importance = MAX(
|
|
// recall_items.importance * ?1,
|
|
// ?2
|
|
// ),
|
|
// updated_at = datetime('now')
|
|
// WHERE recall_items.id IN (
|
|
// SELECT ri.id
|
|
// FROM recall_items ri
|
|
// WHERE ri.importance > ?2
|
|
// AND ri.suppressed_at IS NULL
|
|
// ORDER BY ri.updated_at ASC
|
|
// LIMIT ?3
|
|
// )
|
|
func (q *Queries) DecayRecallImportanceBatch(ctx context.Context, arg DecayRecallImportanceBatchParams) error {
|
|
_, err := q.db.ExecContext(ctx, DecayRecallImportanceBatch, arg.Factor, arg.FloorVal, arg.BatchSize)
|
|
return err
|
|
}
|
|
|
|
const ListArchivalChunksWithoutEmbedding = `-- name: ListArchivalChunksWithoutEmbedding :many
|
|
SELECT id,
|
|
recall_id,
|
|
chunk_index,
|
|
content,
|
|
embedding,
|
|
source,
|
|
hash,
|
|
created_at
|
|
FROM archival_chunks
|
|
WHERE embedding IS NULL
|
|
AND suppressed_at IS NULL
|
|
LIMIT ?1
|
|
`
|
|
|
|
type ListArchivalChunksWithoutEmbeddingParams struct {
|
|
Lim int64 `db:"lim" json:"lim"`
|
|
}
|
|
|
|
type ListArchivalChunksWithoutEmbeddingRow struct {
|
|
ID ids.UUID `db:"id" json:"id"`
|
|
RecallID ids.UUID `db:"recall_id" json:"recall_id"`
|
|
ChunkIndex int64 `db:"chunk_index" json:"chunk_index"`
|
|
Content string `db:"content" json:"content"`
|
|
Embedding memory.Embedding `db:"embedding" json:"embedding"`
|
|
Source string `db:"source" json:"source"`
|
|
Hash string `db:"hash" json:"hash"`
|
|
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
|
}
|
|
|
|
// ListArchivalChunksWithoutEmbedding
|
|
//
|
|
// SELECT id,
|
|
// recall_id,
|
|
// chunk_index,
|
|
// content,
|
|
// embedding,
|
|
// source,
|
|
// hash,
|
|
// created_at
|
|
// FROM archival_chunks
|
|
// WHERE embedding IS NULL
|
|
// AND suppressed_at IS NULL
|
|
// LIMIT ?1
|
|
func (q *Queries) ListArchivalChunksWithoutEmbedding(ctx context.Context, arg ListArchivalChunksWithoutEmbeddingParams) ([]ListArchivalChunksWithoutEmbeddingRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, ListArchivalChunksWithoutEmbedding, arg.Lim)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ListArchivalChunksWithoutEmbeddingRow{}
|
|
for rows.Next() {
|
|
var i ListArchivalChunksWithoutEmbeddingRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.RecallID,
|
|
&i.ChunkIndex,
|
|
&i.Content,
|
|
&i.Embedding,
|
|
&i.Source,
|
|
&i.Hash,
|
|
&i.CreatedAt,
|
|
); 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 UpdateArchivalChunkEmbedding = `-- name: UpdateArchivalChunkEmbedding :exec
|
|
UPDATE archival_chunks
|
|
SET embedding = ?1
|
|
WHERE id = ?2
|
|
`
|
|
|
|
type UpdateArchivalChunkEmbeddingParams struct {
|
|
Embedding memory.Embedding `db:"embedding" json:"embedding"`
|
|
ID ids.UUID `db:"id" json:"id"`
|
|
}
|
|
|
|
// UpdateArchivalChunkEmbedding
|
|
//
|
|
// UPDATE archival_chunks
|
|
// SET embedding = ?1
|
|
// WHERE id = ?2
|
|
func (q *Queries) UpdateArchivalChunkEmbedding(ctx context.Context, arg UpdateArchivalChunkEmbeddingParams) error {
|
|
_, err := q.db.ExecContext(ctx, UpdateArchivalChunkEmbedding, arg.Embedding, arg.ID)
|
|
return err
|
|
}
|