-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
79 lines (64 loc) · 2.04 KB
/
main.cpp
File metadata and controls
79 lines (64 loc) · 2.04 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "ArticleParser.h"
#include "VectorStorage.h"
#include <iostream>
#include <string>
#include <exception>
#include <pqxx/connection.hxx>
int main() {
pqxx::connection conn("host=localhost port=5432 dbname=VectorStore user=postgres password=??????");
char userInput; // user input for options
// options for parsing
std::string parsedJSONpath = "./Data/output"; // path to where JSON files are stored
size_t batchSize = 250; // batch value for parsing to embedding server
size_t maxThreads = 8;
int maxPages = 500; // maximum number of pages to parse (-1 for no limit)
VectorStorage storage(conn, maxThreads); // Initialize vector storage
ArticleParser parser(parsedJSONpath, batchSize, storage, maxPages); // Initialize article parser, used for option 1
// Get user input for options (search, parse, exit)
while (true) {
std::cout << "Select an option:\n";
std::cout << "1. Parse JSON files and store vectors\n";
std::cout << "2. Search\n";
std::cout << "3. Exit\n";
std::cout << "Enter choice (1-3): ";
std::cin >> userInput;
// Parse JSON files and store vectors
if (userInput == '1') {
try {
parser.parseJSONFiles();
}
catch (const std::exception& e) {
std::cerr << "Error during parsing and storing vectors: " << e.what() << std::endl;
}
}
// Search interface
else if (userInput == '2') {
std::cin.ignore(); // clear leftover newline
std::string query;
while (true) {
std::cout << "\nSearch query (or 'exit'): ";
std::getline(std::cin, query);
if (query == "exit" || query.empty())
break;
auto results = storage.search(query, 10);
if (results.empty()) {
std::cout << "No results found.\n";
continue;
}
for (auto& r : results) {
std::cout << "Title: " << r.title << "\n";
std::cout << "Link: " << r.link << "\n";
std::cout << "Score: " << r.score << "\n";
}
}
}
// Exit program
else if (userInput == '3') {
break;
}
else {
std::cout << "Invalid choice. Please try again.\n";
}
}
return 0;
}