UPDATE: Chatbot module
All checks were successful
Build and Release / release (push) Successful in 2m13s

This commit is contained in:
2026-05-05 00:09:55 +07:00
parent 1998cf2ec0
commit a8f0597e59
33 changed files with 1042 additions and 65 deletions

24
db/query/rag.sql Normal file
View File

@@ -0,0 +1,24 @@
-- name: CreateRagChunk :one
INSERT INTO rag_chunks (
id, source_type, source_id, project_id, chunk_index, content, embedding
) VALUES (
COALESCE(sqlc.narg('id')::uuid, uuidv7()),
$1, $2, $3, $4, $5, $6
)
RETURNING *;
-- name: SearchRagChunks :many
SELECT
id, source_type, source_id, project_id, chunk_index, content,
(1 - (embedding <=> sqlc.arg('embedding')))::float8 AS similarity
FROM rag_chunks
WHERE 1=1
AND (sqlc.narg('project_id')::uuid IS NULL OR project_id = sqlc.narg('project_id')::uuid)
AND (sqlc.narg('source_type')::varchar IS NULL OR source_type = sqlc.narg('source_type')::varchar)
AND (1 - (embedding <=> sqlc.arg('embedding')))::float8 >= sqlc.arg('match_threshold')::float8
ORDER BY embedding <=> sqlc.arg('embedding')
LIMIT sqlc.arg('match_count');
-- name: DeleteRagChunksBySourceIDs :exec
DELETE FROM rag_chunks
WHERE source_type = $1 AND source_id = ANY($2::uuid[]);