概述

基于大模型做一个知识库,可以自己搭建一个本地大模型,然后做RAG.

  • 将知识库库进行向量化
  • 查询根据向量查询知识库
  • 将知识库作为提示词丢给大模型,大模型处理后返回结果
    在本地部署大模型,资源要求比较高,还需要做程序定制。

阿里云百炼方案

我们可以在阿里云百炼开通一个大模型,它可以创建应用

  • 在阿里云百炼创建知识库

我们可以在知识库,上传文档。

  • 创建一个应用指向改知识库

基于阿里云百炼创建一个知识库应用_java

集成到应用中

做好应用后,我们可以通过 阿里云百炼提供的接口,查询我们的知识库了。

<code class="language-plain has-numbering hljs" id="code_id_0">package org.example;



import com.alibaba.dashscope.app.*;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import java.util.List;


public class BaiLianExample{
    public static void callAgentApp()
            throws ApiException, NoApiKeyException, InputRequiredException {
        ApplicationParam param = ApplicationParam.builder()
				//使用自己的apikey
                .apiKey("sk-b8d405687fd74a81889195a41da78FF")
                .appId("6bfe00af4fb34ab4b1dfc8387e57f8fc")
                .prompt("jpaas 如何在某个java 方法上记录日志")
                .temperature(0F)
                .build();

        Application application = new Application();
        ApplicationResult result = application.call(param);

        System.out.printf("requestId: %s, text: %s, finishReason: %s\n",
                result.getRequestId(), result.getOutput().getText(), result.getOutput().getFinishReason());
    }

    public static void main(String[] args) {
        try {
            callAgentApp();
        } catch (ApiException | NoApiKeyException | InputRequiredException e) {
            System.out.printf("Exception: %s", e.getMessage());
        }
        System.exit(0);
    }
}</code>
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.

上传了两个文档,并测试了一下,我们查询文档是生效的。