Baptistabomb
Baptistabomb
Explore posts from servers
DTDrizzle Team
Created by Baptistabomb on 4/10/2024 in #help
How to migrate this betterSqlite3 query to drizzle
export const search = async (
text: string,
{ filterId }: { filterId?: string } = {},
) => {
if (!text) return [];

const vector = await getEmbedding(text);
const searchQuery = db.prepare(`
WITH matching_products AS (
SELECT rowid, distance
FROM products_vss
WHERE vss_search(vector, ?)
${filterId ? 'AND rowid != ?' : ''}
AND distance < 1.5
ORDER BY distance ASC
LIMIT 5
)
SELECT p.*, mp.distance
FROM products p
INNER JOIN matching_products mp ON p.id = mp.rowid;
`);

return searchQuery.all(JSON.stringify(vector), filterId) as Product[];
};
export const search = async (
text: string,
{ filterId }: { filterId?: string } = {},
) => {
if (!text) return [];

const vector = await getEmbedding(text);
const searchQuery = db.prepare(`
WITH matching_products AS (
SELECT rowid, distance
FROM products_vss
WHERE vss_search(vector, ?)
${filterId ? 'AND rowid != ?' : ''}
AND distance < 1.5
ORDER BY distance ASC
LIMIT 5
)
SELECT p.*, mp.distance
FROM products p
INNER JOIN matching_products mp ON p.id = mp.rowid;
`);

return searchQuery.all(JSON.stringify(vector), filterId) as Product[];
};
1 replies