@PostMapping("/datasource")
    @CrossOrigin
    public ActionResult embeddings(@Valid TableMilvusQueryRequest request)
        throws Exception {

        // query tables
        request.setPageNo(1);
        request.setPageSize(1000);
        TablePageQueryParam queryParam = rdbWebConverter.tablePageRequest2param(request);
        TableSelector tableSelector = new TableSelector();
        tableSelector.setColumnList(false);
        tableSelector.setIndexList(false);
        PageResult<Table> tableDTOPageResult = tableService.pageQuery(queryParam, tableSelector);

        List<Table> tables = tableDTOPageResult.getData();
        if (CollectionUtils.isEmpty(tables)) {
            return ActionResult.isSuccess();
        }

        String tableName = tables.get(0).getName();
        String tableSchema = queryTableDdl(tableName, request);

        if (StringUtils.isBlank(tableSchema)) {
            throw new ParamBusinessException("tableSchema is empty");
        }

        // save first table embedding
        TableSchemaRequest tableSchemaRequest = new TableSchemaRequest();
        tableSchemaRequest.setDataSourceId(request.getDataSourceId());
        tableSchemaRequest.setApiKey(request.getApikey());
        tableSchemaRequest.setDeleteBeforeInsert(true);
        tableSchemaRequest.setDataSourceSchema(request.getSchemaName());
        tableSchemaRequest.setDatabaseName(request.getDatabaseName());

        saveTableEmbedding(tableSchema, tableSchemaRequest);

        // save other table embedding
        tableSchemaRequest.setDeleteBeforeInsert(false);
        for (int i = 1; i < tables.size(); i++) {
            tableName = tables.get(i).getName();
            tableSchema = queryTableDdl(tableName, request);
            if (StringUtils.isBlank(tableSchema)) {
                continue;
            }
            saveTableEmbedding(tableSchema, tableSchemaRequest);
        }

        // query all the tables
        Long totalTableCount = tableDTOPageResult.getTotal();
        Integer pageSize = queryParam.getPageSize();
        if (pageSize < totalTableCount) {
            for (int i = 2; i < totalTableCount/pageSize + 1; i++) {
                queryParam.setPageNo(i);
                tableDTOPageResult = tableService.pageQuery(queryParam, tableSelector);
                tables = tableDTOPageResult.getData();
                for (Table table : tables) {
                    tableName = table.getName();
                    tableSchema = queryTableDdl(tableName, request);
                    if (StringUtils.isBlank(tableSchema)) {
                        continue;
                    }
                    saveTableEmbedding(tableSchema, tableSchemaRequest);
                }
            }
        }

        return ActionResult.isSuccess();
    }
save datasource embeddings

@param request
@return
@throws IOException
chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/EmbeddingController.java