"use strict";
/**
 * Postgres vector DB (e.g. pgvector) RAG parser.
 * Detects Postgres spans used for vector search and returns standard RAGCall[].
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.postgresVectorDbRagParser = void 0;
const utils_1 = require("../utils");
const SYSTEM_NAME = 'postgresql';
const DB_SYSTEM = 'db.system';
const DB_SYSTEM_NAME = 'db.system.name';
function isPostgresVectorSpan(span) {
    const attrs = span.attributes ?? {};
    const res = span.resourceAttributes ?? {};
    const sys = attrs[DB_SYSTEM_NAME] ?? attrs[DB_SYSTEM] ?? res[DB_SYSTEM_NAME] ?? res[DB_SYSTEM];
    const sysStr = sys != null ? String(sys).toLowerCase() : '';
    if (sysStr.includes('postgres') || sysStr === 'pgvector') {
        const name = (span.name ?? '').toLowerCase();
        const stmt = (attrs['db.statement'] ?? attrs['db.query.summary'] ?? '').toString().toLowerCase();
        return (name.includes('vector') ||
            name.includes('pgvector') ||
            stmt.includes('vector') ||
            stmt.includes('embedding') ||
            stmt.includes('<=>') ||
            stmt.includes('<->'));
    }
    const name = (span.name ?? '').toLowerCase();
    const svc = (span.serviceName ?? '').toLowerCase();
    return ((name.includes('pgvector') || svc.includes('pgvector')) ||
        (name.includes('postgres') && (name.includes('vector') || name.includes('similarity'))));
}
exports.postgresVectorDbRagParser = {
    name: 'postgres-vectordb',
    canParse(spans) {
        return (spans ?? []).some(isPostgresVectorSpan);
    },
    parse(spans) {
        return (spans ?? [])
            .filter(isPostgresVectorSpan)
            .map((span) => (0, utils_1.buildRAGCall)(span, { systemName: SYSTEM_NAME }));
    },
};
//# sourceMappingURL=postgresVectorDb.js.map