Neon SQL function Invalid using Prisma

67 views Asked by At

Hi I am making a web app in nextjs using neon database and prisma. I am using vectors within my database, and when trying to access the data to retrieve a document embeddings using vectors, it does not let me call the function.

/api/message POST:

    const embeddingResponse = await openai.embeddings.create({
        model: 'text-embedding-ada-002',
        input,
    })

    const [{ embedding }] = embeddingResponse.data

 const query_embedding: number[] = embedding // openai embedding response
        const match_threshold: number = .73
        const match_count: number = 4
        const data = await prisma.$queryRaw`SELECT * FROM match_documents(${query_embedding}, ${match_threshold}, ${match_count})`

SQL:

create or replace function match_documents (
  query_embedding vector(1536),
  match_threshold float,
  match_count int
)
returns table (
  id text,
  content text,
  similarity float
)
language sql stable
as $$
  select
    sources.id,
    sources.content,
    1 - (sources.vector <=> query_embedding) as similarity
  from sources
  where 1 - (sources.vector <=> query_embedding) > match_threshold
  order by similarity desc
  limit match_count;
$$;

Error:

Invalid `prisma.$queryRaw()` invocation:

    Raw query failed. Code: `42883`. Message: `ERROR: function match_documents(numeric[], numeric, bigint) does not exist
    HINT: No function matches the given name and argument types. You might need to add explicit type casts.`
        at .... {
      code: 'P2010',
      clientVersion: '5.5.2',
      meta: {
        code: '42883',
        message: 'ERROR: function match_documents(numeric[], numeric, bigint) does not exist\n' +
          'HINT: No function matches the given name and argument types. You might need to add explicit type casts.'
      }
    }

Thanks!

0

There are 0 answers