问题
在学习spring-ai-alibaba时,发现1.0.0.2版本在自动装配DashScopeCloudStore时,会报如下错误:
Field dashScopeCloudStore in com.example.spring_ai_alibaba_examples.examples.SpringAiAlibabaExample01 required a bean of type 'com.alibaba.cloud.ai.dashscope.rag.DashScopeCloudStore' that could not be found.
意思是没有找到DashScopeCloudStore
原因分析
查看了一下spring-ai-alibaba-autoconfigure-dashscope包里确实没有提供对应的Bean,也就是说该类没有自动装配
上网搜了一下,发现1.0.0-M6.1版本已经有人提出过这个问题了(DashScopeCloudStore Auto-configuration 注入问题 · Issue #84 · springaialibaba/spring-ai-alibaba-website),仍然是open状态,尚未解决
问题解决
那就只能自己创建一个了
this.dashScopeCloudStore = new DashScopeCloudStore(DashScopeApi.builder().apiKey("your api key").build(), new DashScopeStoreOptions("知识库名称"));
这只是一个最简化样例,在创建DashScopeApi和DashScopeStoreOptions的时候可以添加许多其他参数
优化建议
建议官方提供一个自动装配的DashScopeApi
然后就可以通过以下方式使用DashScopeCloudStore
@Beanpublic DashScopeCloudStore dashScopeCloudStore(DashScopeApi dashScopeApi) {return new DashScopeCloudStore(dashScopeApi, new DashScopeStoreOptions("测试库"));}