/* * Copyright (C) 2024 Petr Mironychev * * This file is part of QodeAssist. * * QodeAssist 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. * * QodeAssist 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 QodeAssist. If not, see . */ #pragma once #include #include #include #include #include "RAGStorage.hpp" #include "RAGVectorizer.hpp" #include namespace ProjectExplorer { class Project; } namespace QodeAssist::Context { class RAGManager : public QObject { Q_OBJECT public: static RAGManager &instance(); // struct SearchResult // { // QString filePath; // float l2Score; // float cosineScore; // bool operator<(const SearchResult &other) const; // }; struct SearchResult { QString filePath; float semantic_similarity; float structural_similarity; float combined_score; bool operator<(const SearchResult &other) const { return combined_score > other.combined_score; } }; // Process and vectorize files QFuture processFiles(ProjectExplorer::Project *project, const QStringList &filePaths); std::optional loadVectorFromStorage( ProjectExplorer::Project *project, const QString &filePath); QStringList getStoredFiles(ProjectExplorer::Project *project) const; bool isFileStorageOutdated(ProjectExplorer::Project *project, const QString &filePath) const; RAGVectorizer *getVectorizer() const { return m_vectorizer.get(); } // Search functionality QFuture> search( const QString &text, ProjectExplorer::Project *project, int topK = 5); void searchSimilarDocuments(const QString &text, ProjectExplorer::Project *project, int topK = 5); void logSearchResults(const QList &results) const; signals: void vectorizationProgress(int processed, int total); void vectorizationFinished(); private: RAGManager(QObject *parent = nullptr); ~RAGManager(); RAGManager(const RAGManager &) = delete; RAGManager &operator=(const RAGManager &) = delete; QFuture processFile(ProjectExplorer::Project *project, const QString &filePath); void processNextBatch( std::shared_ptr> promise, ProjectExplorer::Project *project, const QStringList &files, int startIndex, int batchSize); void ensureStorageForProject(ProjectExplorer::Project *project); QString getStoragePath(ProjectExplorer::Project *project) const; std::unique_ptr m_vectorizer; std::unique_ptr m_currentStorage; ProjectExplorer::Project *m_currentProject{nullptr}; std::optional loadFileContent(const QString &filePath); }; } // namespace QodeAssist::Context