feat: implement lexical search functionality in RAG, including new SQL queries and service methods
Build and Release / release (push) Failing after 1m34s
Build and Release / release (push) Failing after 1m34s
This commit is contained in:
@@ -0,0 +1 @@
|
||||
DROP INDEX IF EXISTS idx_rag_chunks_content_trgm;
|
||||
@@ -0,0 +1,4 @@
|
||||
CREATE EXTENSION IF NOT EXISTS pg_trgm;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_rag_chunks_content_trgm
|
||||
ON rag_chunks USING GIN (content gin_trgm_ops);
|
||||
@@ -19,6 +19,42 @@ WHERE 1=1
|
||||
ORDER BY embedding <=> sqlc.arg('embedding')
|
||||
LIMIT sqlc.arg('match_count');
|
||||
|
||||
-- name: SearchRagChunksLexical :many
|
||||
WITH terms AS (
|
||||
SELECT DISTINCT trim(term) AS term
|
||||
FROM unnest(sqlc.arg('terms')::text[]) AS term
|
||||
WHERE trim(term) <> ''
|
||||
),
|
||||
matched AS (
|
||||
SELECT
|
||||
r.id,
|
||||
r.source_type,
|
||||
r.source_id,
|
||||
r.project_id,
|
||||
r.chunk_index,
|
||||
r.content,
|
||||
r.created_at,
|
||||
r.updated_at,
|
||||
COUNT(*)::float8 AS similarity
|
||||
FROM rag_chunks r
|
||||
JOIN terms t ON r.content ILIKE '%' || t.term || '%'
|
||||
WHERE (sqlc.narg('project_id')::uuid IS NULL OR r.project_id = sqlc.narg('project_id')::uuid)
|
||||
GROUP BY
|
||||
r.id,
|
||||
r.source_type,
|
||||
r.source_id,
|
||||
r.project_id,
|
||||
r.chunk_index,
|
||||
r.content,
|
||||
r.created_at,
|
||||
r.updated_at
|
||||
)
|
||||
SELECT
|
||||
id, source_type, source_id, project_id, chunk_index, content, created_at, updated_at, similarity
|
||||
FROM matched
|
||||
ORDER BY similarity DESC, chunk_index ASC
|
||||
LIMIT sqlc.arg('match_count');
|
||||
|
||||
-- name: DeleteRagChunksBySourceIDs :exec
|
||||
DELETE FROM rag_chunks
|
||||
WHERE source_type = $1 AND source_id = ANY($2::uuid[]);
|
||||
|
||||
Reference in New Issue
Block a user