pgvector / pgvector-node

pgvector support for Node.js, Deno, and Bun (and TypeScript)
MIT License
335 stars 11 forks source link

Distance column param issue with sequelize #17

Closed fTrestour closed 9 months ago

fTrestour commented 9 months ago

Hi!

I'm new to this library and I'm trying to run this query with sequelize:

const lessons = await Table.findAll({
      include: [
        {
          association: 'association',
        },
      ],
      order: cosineDistance('Table.embedding_column', searchEmbedding, sequelize),
      subQuery: false,
      limit: 15,
    })

Sequelize makes it necessary to specify Table. in this situation and the distance function from the package generates "Table.embedding_column" <=> ... while it should be "Table"."embedding_column" <=> ... to have it work properly.

I am missing something or is this a bug?

If it's a bug, I guess a split on . for the column arg and mapping sequelize.dialect.queryGenerator.quoteIdentifier to each element here could be a fix?

ankane commented 9 months ago

Hi @fTrestour, quoting the column is by design. Added support for passing sequelize.literal('"Table".embedding_column') in the commit above.