Giter VIP home page Giter VIP logo

Comments (2)

gajus avatar gajus commented on June 2, 2024 1

pgvector does support Slonik.

https://github.com/pgvector/pgvector-node/?tab=readme-ov-file#slonik

from slonik.

jimlloyd avatar jimlloyd commented on June 2, 2024

This must be why I have not been able to make progress after my first few hours with slonik.

I create a table with

        await pool.connect(async connection =>
        {
            // We just created a new database so we do not need `IF NOT EXISTS` for any of these entities
            await connection.query(sql.unsafe`CREATE EXTENSION vector`);

            /// MEM CONTENT
            await connection.query(sql.unsafe`CREATE TABLE mem(
                id BIGINT PRIMARY KEY,     -- bun.hash
                content TEXT NOT NULL,
                embed_vector vector(768) NOT NULL,
                tssearch tsvector GENERATED ALWAYS AS (to_tsvector('english', content)) STORED,
                tokens INT NOT NULL)`
            );
     }

And then I try to insert data with

async function createMem(content: string) : Promise<Mem> {
    const mem: Mem = Mem.parse({
        id: BigInt(Bun.hash(content)),
        content: content,
        embed_vector: await embedding.generateOne(content),
        tokens: count_tokens(content)
    })
    return mem;
}

    return await pool.connect(async connection => {
        // A Mem is entirely determined from its content, so we only pass in the content to this function,
        // and then construct the Mem from the content.
        const mem: Mem = await createMem(content);

        try {
            const insertMemQuery = sql.type(Mem)`
                INSERT INTO mem (id, content, embed_vector, tokens)
                VALUES (${mem.id}, ${mem.content}, ${mem.embed_vector}, ${mem.tokens})`;

            await connection.query(insertMemQuery);
            // TODO validate result
        } catch (err) {
            console.error((err as Error).stack)
            throw err;
        }

I get this error:

Error: Expected token to include "type" property.
    at isSqlToken (/Users/jim.lloyd/hub/Memento/node_modules/slonik/dist/utilities/isSqlToken.js:29:14)
    at createFragment (/Users/jim.lloyd/hub/Memento/node_modules/slonik/dist/factories/createSqlTag.js:39:22)
    at <anonymous> (/Users/jim.lloyd/hub/Memento/node_modules/slonik/dist/factories/createSqlTag.js:135:20)
    at <anonymous> (/Users/jim.lloyd/hub/Memento/src/lib/postgresdb.ts:127:30)
    at asyncFunctionResume (native)
    at promiseReactionJobWithoutPromiseUnwrapAsyncContext (native)
    at promiseReactionJob (native)
    at processTicksAndRejections (native)
UnexpectedStateError: Expected token to include "type" property.

pgvector is a requirement for the app I want to build. slonik looks very cool but perhaps I have to find some other alternative? Is there a workaround until this issue is addressed?

from slonik.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.