weaviate / typescript-client

Official Weaviate TypeScript Client
https://www.npmjs.com/package/weaviate-ts-client
BSD 3-Clause "New" or "Revised" License
57 stars 21 forks source link

Cannot get generative search results and object ID together #107

Open itsajchan opened 5 months ago

itsajchan commented 5 months ago

When making a generative search query and requesting the id in the latest ts client (2.0.0) available on NPM, it's not possible to get both the ID and a generated singleResult together in a single query.

So the following doesn't work:

   const result = await client.graphql
        .get()
        .withClassName('Question')
        .withFields('name answer _additional { id}')
        .withGenerate({singlePrompt: 'Explain {answer} as you might to a five-year-old.'})
        .withLimit(1)
        .do();

This work around appears to work but doesn't align with the expected developer experience:

   const generatePrompt = 'Explain {answer} as you might to a five-year-old.'
    const result = await client.graphql
        .get()
        .withClassName('Question')
        .withFields(`name answer { id generate ( singleResult: { prompt:\"${generatePrompt}\"}){error singleResult } }`)
        .withLimit(1)
        .do();

Which produces the desired output of the generated result and the id together.

larryhudson commented 4 months ago

Hi there, I'm dealing with this same issue. Thanks for posting the workaround - I can confirm that's working for me, but would be good to get this bug fixed.

I've made a minimal repo reproducing this issue here: https://github.com/larryhudson/astro-weaviate-generative-id-troubleshooting

I've also asked about this in the Weaviate Slack support channel but haven't got an answer yet.

larryhudson commented 1 month ago

This is still an issue, I just ran into it again.