smollerGraph 0.20.2
A small graph database, from scratch
Loading...
Searching...
No Matches
api.h
Go to the documentation of this file.
1#ifndef SMOLLERGRAPH_API_H_
2#define SMOLLERGRAPH_API_H_
3
4#include <string>
5#include <string_view>
6#include <vector>
7
8#include "absl/status/statusor.h"
10
11namespace smollergraph {
12
13// What sg serve answers with, as JSON. It's kept apart from HTTP, so the tests
14// can check it without a server.
15
16// Returns `text` as a JSON string: in quotes, with quotes, backslashes and
17// control characters escaped.
18std::string JsonString(std::string_view text);
19
20// Returns properties as a JSON object, with a field for each key.
21std::string PropertiesJson(const std::vector<Property>& properties);
22
23// Returns an error's message as JSON, for the UI to show.
24std::string ErrorJson(std::string_view message);
25
26// Returns a few of the graph's names that start with `prefix`, in order, for
27// the UI to suggest.
28std::string NamesJson(const Graph& graph, std::string_view prefix);
29
30// Returns node `id`'s record as it's kept on disk: its label, its page, its
31// offset in the page and its bytes, then its chains of relationships out and
32// in, newest first, each with its properties, the node at its other end and
33// where it's kept, and its chain of properties, newest first, each with where
34// it's kept. An id the graph doesn't have is an error.
35absl::StatusOr<std::string> NodeJson(const Graph& graph, std::string_view id);
36
37// Parses, plans and runs a query in our subset of Cypher, from a request. It
38// answers with the columns and up to kMaxRows of the rows, each value with the
39// id of its node, and the nodes the rows return, a path's nodes among them, up
40// to kMaxDrawn of them, with the relationships between them and their
41// properties, for the page to draw. It says how long the
42// query took on the server, and how many pages it read. After EXPLAIN, it
43// answers with the plan, and it says what's wrong with a query it can't run.
44inline constexpr size_t kMaxRows = 1000;
45// How many of the most similar nodes the page draws.
46inline constexpr size_t kSimilar = 10;
47inline constexpr size_t kMaxDrawn = 500;
48absl::StatusOr<std::string> QueryJson(const Graph& graph,
49 std::string_view text);
50
51// Returns the kSimilar nodes whose embeddings are most like node `id`'s, the
52// most alike first, each with its name, its label and its cosine. An id the
53// graph doesn't have is an error, and so is a graph without embeddings.
54absl::StatusOr<std::string> SimilarJson(const Graph& graph,
55 std::string_view id);
56
57} // namespace smollergraph
58
59#endif // SMOLLERGRAPH_API_H_
A graph kept in three files of records, one for nodes, one for relationships and one for their proper...
Definition graph.h:113
std::vector< Property > properties
Definition facts.cc:19
std::string_view text
Definition facts.cc:17
std::string PropertiesJson(const std::vector< Property > &properties)
Returns properties as a JSON object, with a field for each key.
Definition api.cc:107
absl::StatusOr< std::string > SimilarJson(const Graph &graph, std::string_view id)
Returns the kSimilar nodes whose embeddings are most like node id's, the most alike first,...
Definition api.cc:234
absl::StatusOr< std::string > QueryJson(const Graph &graph, std::string_view text)
Definition api.cc:158
absl::StatusOr< std::string > NodeJson(const Graph &graph, std::string_view id)
Returns node id's record as it's kept on disk: its label, its page, its offset in the page and its by...
Definition api.cc:130
constexpr size_t kSimilar
How many of the most similar nodes the page draws.
Definition api.h:46
std::string ErrorJson(std::string_view message)
Returns an error's message as JSON, for the UI to show.
Definition api.cc:126
std::string JsonString(std::string_view text)
What sg serve answers with, as JSON.
Definition api.cc:90
constexpr size_t kMaxDrawn
Definition api.h:47
std::string NamesJson(const Graph &graph, std::string_view prefix)
Returns a few of the graph's names that start with prefix, in order, for the UI to suggest.
Definition api.cc:116
constexpr size_t kMaxRows
Parses, plans and runs a query in our subset of Cypher, from a request.
Definition api.h:44