SAI知识库助手 - 使用文档

介绍

基于 saiadmin 开发的AI助手

支持版本

saiadmin6.x

安装

直接在插件市场下载压缩包并安装

配置

知识库数据向量化,需要用到 队列处理 ,我们使用的是官方的 webman/redis-queue 组件,需要手动配置一下

找到 server\config\plugin\webman\redis-queue\process.php , 加入以下配置

<?php
return [
    'consumer'  => [
        'handler'     => Webman\RedisQueue\Process\Consumer::class,
        'count'       => 8, // 可以设置多进程同时消费
        'constructor' => [
            // 消费者类目录
            'consumer_dir' => app_path() . '/queue/redis',
            'consumer_dir' => base_path() . '/plugin/sai/queue/redis', // SAI 插件配置的队列
        ]
    ]
];

知识库支持 本地PostgreSQL 两种方式, 默认使用 Eloquent ORM

1、 本地非常简单,只需要在配置的时候加入一个目录,目录保存到本地 runtime

2、 PGSQL配置

找到 server\config\database.php , 加入 pgsql 配置

<?php
'pgsql' => [
    'driver' => 'pgsql',
    'host' => '127.0.0.1',
    'port' => 5432,
    'database' => 'postgres',
    'username' => 'postgres',
    'password' => 'postgres',
    'charset' => 'utf8',
    'prefix' => '',
    'schema' => 'public',
    'sslmode' => 'prefer',
    'pool' => [ // 连接池配置,仅支持swoole/swow驱动
        'max_connections' => 5, // 最大连接数
        'min_connections' => 1, // 最小连接数
        'wait_timeout' => 3,    // 从连接池获取连接等待的最大时间,超时后会抛出异常
        'idle_timeout' => 60,   // 连接池中连接最大空闲时间,超时后会关闭回收,直到连接数为min_connections
        'heartbeat_interval' => 50, // 连接池心跳检测时间,单位秒,建议小于60秒
    ],
]

向量处理过程中,系统会自动创建表

CREATE TABLE document_chunks (
    id BIGSERIAL PRIMARY KEY,
    document_id INTEGER NOT NULL,
    knowledge_id INTEGER NOT NULL,
    content TEXT NOT NULL,
    embedding vector({$this->vectorDimension}),
    metadata JSONB DEFAULT '{}',
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)