Repository navigation
Expand file tree
/
Copy pathclient.h
More file actions
68 lines (52 loc) · 1.99 KB
/
Copy pathclient.h
File metadata and controls
68 lines (52 loc) · 1.99 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
/**
* HTTP client for Ragger Memory daemon
*
* Thin client that mirrors RaggerMemory interface but uses HTTP API.
* Used by CLI when daemon is running — avoids loading the embedding model.
*/
#pragma once
#include <string>
#include <vector>
#include <optional>
#include "nlohmann_json.hpp"
#include "storage_types.h"
namespace ragger {
using json = nlohmann::json;
class RaggerClient {
public:
RaggerClient(const std::string& host = "127.0.0.1", int port = 8432,
const std::string& token = "");
/// Check if the daemon is running (GET /health succeeds)
bool is_available() const;
/// Store a memory via HTTP. Returns memory ID.
std::string store(const std::string& text, json metadata = {});
/// Search via HTTP.
SearchResponse search(const std::string& query, int limit = 5,
float min_score = 0.0f,
std::vector<std::string> collections = {});
/// Get count via HTTP.
int count();
/// Delete a memory via HTTP.
bool delete_memory(int memory_id);
/// Delete batch via HTTP.
int delete_batch(const std::vector<int>& memory_ids);
/// Search by metadata via HTTP.
std::vector<SearchResult> search_by_metadata(const json& metadata_filter, int limit = 0);
/// Register user via HTTP POST /register.
json register_user(const std::string& username);
private:
std::string host_;
int port_;
std::string token_;
/// Make an HTTP request. Returns {status_code, response_body}.
struct HttpResponse {
int status;
std::string body;
};
HttpResponse http_get(const std::string& path) const;
HttpResponse http_post(const std::string& path, const std::string& body) const;
HttpResponse http_delete(const std::string& path) const;
HttpResponse http_request(const std::string& method, const std::string& path,
const std::string& body = "") const;
};
} // namespace ragger