Skip to content

alternative ways to optimize vector filtering #175

@saihaj

Description

@saihaj

wondering if we rewrite this as CTE that might speed things up? need to check some queries to confirm.

const embeddingsQuery = await db
.select({
text: billVector.text,
documentId: billVector.document,
title: document.title,
source: document.source,
distance: sql`vector_distance_cos(${billVector.vector}, vector32(${termEmbeddingString}))`,
})
.from(billVector)
.where(
and(
sql`vector_distance_cos(${billVector.vector}, vector32(${termEmbeddingString})) < ${VECTOR_SEARCH_MATCH_THRESHOLD}`,
isNotNull(billVector.document),
eq(billVector.source, WEB_SOURCE),
),
)
.orderBy(
sql`vector_distance_cos(${billVector.vector}, vector32(${termEmbeddingString})) ASC`,
)
.leftJoin(document, eq(document.id, billVector.document))
.limit(LIMIT);

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions