/*
 * Copyright (C) 2024 KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <https://www.gnu.org/licenses/>.
 */

#pragma once

#include <rpc/vectorDB/vectorDatabase.h>

#include <nlohmann/json.hpp>

struct KnowledgebaseSearchResult {
    std::string documents;
    std::string source;
    double similarity;
};

using KnowledgebaseSearchResults = std::vector<KnowledgebaseSearchResult>;

struct KnowledgeFileInfo {
    std::string filepath;
    std::vector<std::vector<float>> vectors;
    std::vector<std::string> documents;
    std::string knowledgeBaseName;
};

struct InputParameters {
    std::string filepath;
    std::string knowledgeBaseName;
};

class KnowledgebaseVectorDatabase {
public:
    bool createCollection(std::string& collectionName);
    bool deleteCollection(const std::string& collectionName);

    bool insertVectorData(const std::vector<KnowledgeFileInfo>& vectorInfos);

    KnowledgebaseSearchResults similaritySearch(const std::string& knowledgeBaseName,
                                                const std::vector<float>& vector) const;
    ~KnowledgebaseVectorDatabase() = default;

private:
    KnowledgebaseSearchResults transformSearchResults(VectorDB::SearchResults results) const;
};