This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

at main 2.4 kB View raw
1import pg from "pg"; 2import { readFileSync } from "node:fs"; 3function loadConn() { 4 if (process.env.DB_CONNECTION_STRING) return process.env.DB_CONNECTION_STRING; 5 for (const p of ["../.env", ".env"]) { 6 try { const m = readFileSync(p, "utf8").match(/^\s*DB_CONNECTION_STRING\s*=\s*(.+)\s*$/m); if (m) return m[1].trim(); } catch {} 7 } 8 throw new Error("no conn"); 9} 10const pool = new pg.Pool({ connectionString: loadConn(), ssl: { rejectUnauthorized: false }, max: 3 }); 11 12console.log("=== full tangled_readmes columns ==="); 13console.table((await pool.query(` 14 select c.ordinal_position, c.column_name, c.data_type, c.udt_name, c.is_nullable 15 from information_schema.columns c 16 where c.table_schema='public' and c.table_name='tangled_readmes' 17 order by c.ordinal_position`)).rows); 18 19console.log("\n=== embedding column: pgvector dimensions ==="); 20console.table((await pool.query(` 21 select a.attname, format_type(a.atttypid, a.atttypmod) as type 22 from pg_attribute a 23 join pg_class c on c.oid=a.attrelid join pg_namespace n on n.oid=c.relnamespace 24 where n.nspname='public' and c.relname='tangled_readmes' and a.attnum>0 and not a.attisdropped 25 and format_type(a.atttypid,a.atttypmod) ~* 'vector'`)).rows); 26 27console.log("\n=== counts ==="); 28console.table((await pool.query(` 29 select 30 count(*)::int total, 31 count(*) filter (where embedding is not null)::int with_embedding, 32 count(distinct embedding_model)::int models 33 from tangled_readmes`)).rows); 34 35console.log("\n=== embedding_model values ==="); 36console.table((await pool.query(`select embedding_model, count(*)::int n from tangled_readmes group by 1 order by 2 desc`)).rows); 37 38console.log("\n=== indexes on tangled_readmes (ivfflat/hnsw?) ==="); 39console.table((await pool.query(`select indexname, indexdef from pg_indexes where schemaname='public' and tablename='tangled_readmes'`)).rows); 40 41console.log("\n=== sample row (text truncated, embedding omitted) ==="); 42const s = await pool.query(`select * from tangled_readmes limit 1`); 43if (s.rows.length) { 44 const r = { ...s.rows[0] }; 45 for (const k of Object.keys(r)) { 46 if (k === "embedding") r[k] = `<vector len=${typeof r[k] === "string" ? (r[k].match(/,/g)?.length ?? 0) + 1 : "?"}>`; 47 else if (typeof r[k] === "string" && r[k].length > 160) r[k] = r[k].slice(0, 160) + "…"; 48 } 49 console.log(JSON.stringify(r, null, 2)); 50} 51await pool.end();