typescript-client icon indicating copy to clipboard operation
typescript-client copied to clipboard

Cannot get generative search results and object ID together

Open itsajchan opened this issue 2 years ago • 3 comments

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.

itsajchan avatar Jan 18 '24 05:01 itsajchan

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 avatar Feb 10 '24 06:02 larryhudson

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

larryhudson avatar May 03 '24 11:05 larryhudson

Hey, this should be available in the new client version - have you given it a try?

malgamves avatar Jan 10 '25 15:01 malgamves

This was a limitation of the old GraphQL builder API. In the v3 client every result carries its uuid alongside the generated text, so you get both without the workaround.

Docs: https://docs.weaviate.io/weaviate/search/generative

Closing. Thanks @larryhudson for the reproduction repo back then.

g-despot avatar Sep 01 '26 08:09 g-despot