Cannot get generative search results and object ID together
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.
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.
This is still an issue, I just ran into it again.
Hey, this should be available in the new client version - have you given it a try?
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.