Skip to content

Commit

Permalink
Merge pull request #3264 from esen/fix_pg_memory_query
Browse files Browse the repository at this point in the history
Fix PG query: Use only 'text' subfield name, field name is not needed here
  • Loading branch information
lalalune authored Feb 5, 2025
2 parents a457d61 + 71a9c74 commit fd64139
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
11 changes: 5 additions & 6 deletions packages/adapter-pglite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -828,12 +828,12 @@ export class PGLiteDatabaseAdapter
SELECT
embedding,
COALESCE(
content->$2->>$3,
content->>$2,
''
) as content_text
FROM memories
WHERE type = $4
AND content->$2->>$3 IS NOT NULL
WHERE type = $3
AND content->>$2 IS NOT NULL
)
SELECT
embedding,
Expand All @@ -845,17 +845,16 @@ export class PGLiteDatabaseAdapter
WHERE levenshtein(
$1,
content_text
) <= $6 -- Add threshold check
) <= $5 -- Add threshold check
ORDER BY levenshtein_score
LIMIT $5
LIMIT $4
`;

const { rows } = await this.query<{
embedding: number[];
levenshtein_score: number;
}>(sql, [
opts.query_input,
opts.query_field_name,
opts.query_field_sub_name,
opts.query_table_name,
opts.query_match_count,
Expand Down
11 changes: 5 additions & 6 deletions packages/adapter-postgres/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1016,12 +1016,12 @@ export class PostgresDatabaseAdapter
SELECT
embedding,
COALESCE(
content->$2->>$3,
content->>$2,
''
) as content_text
FROM memories
WHERE type = $4
AND content->$2->>$3 IS NOT NULL
WHERE type = $3
AND content->>$2 IS NOT NULL
)
SELECT
embedding,
Expand All @@ -1033,14 +1033,13 @@ export class PostgresDatabaseAdapter
WHERE levenshtein(
$1,
content_text
) <= $6 -- Add threshold check
) <= $5 -- Add threshold check
ORDER BY levenshtein_score
LIMIT $5
LIMIT $4
`;

const { rows } = await this.pool.query(sql, [
opts.query_input,
opts.query_field_name,
opts.query_field_sub_name,
opts.query_table_name,
opts.query_match_count,
Expand Down

0 comments on commit fd64139

Please sign in to comment.