You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Weaviate JavaScript客户端.withAsk返回undefined问题排查

问题解决:Weaviate Ask功能返回undefined

问题概述

已完成Weaviate云集群部署,数据导入成功且客户端连接正常,但执行Ask功能代码后返回undefined,预期应返回Sarah Mitchell。

直接原因:函数未返回查询结果

你的question函数缺少返回语句,导致异步函数默认返回undefined,这是核心问题:

export async function question(collection: Collections, question: string) {
  // 未返回查询结果,函数默认返回undefined
  await client.graphql
    .get()
    .withClassName(collection)
    .withAsk({ question })
    .withFields('memberName _additional { answer { hasAnswer property result startPosition endPosition } }')
    .withLimit(5)
    .do()
}

修复步骤

1. 修复函数返回值

修改question函数,添加return语句返回GraphQL查询结果:

export async function question(collection: Collections, question: string) {
  // 添加return返回查询结果
  return await client.graphql
    .get()
    .withClassName(collection)
    .withAsk({ question })
    .withFields('memberName _additional { answer { hasAnswer property result startPosition endPosition } }')
    .withLimit(5)
    .do()
}

2. 验证配套配置与数据

从你提供的信息来看,Schema和数据导入均无明显问题,但可额外确认:

  • 确认Weaviate云集群已正确配置OpenAI API密钥(qna-openai模块依赖该密钥)
  • 确认Sarah Mitchell的hobbies字段确实包含与绘画相关的内容(你已验证此点)

3. 优化查询字段(可选)

调整返回字段,让结果更直观:

.withFields('memberName hobbies _additional { answer { hasAnswer result } }')

验证修复

执行修改后的代码,即可得到包含Sarah Mitchell的预期结果:

question(Collections.TeamMember, 'Who has painting as a hobby?')
  .then((result) => { console.log(result) });

内容的提问来源于stack exchange,提问作者Remi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 00:47:03