@littlebigbrain/client 0.13.1 → 0.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +103 -88
- package/dist/client.d.ts +6 -1
- package/dist/client.js +10 -1
- package/dist/namespaces.d.ts +85 -1
- package/dist/namespaces.js +175 -3
- package/dist/schema.d.ts +4498 -207
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,129 +1,144 @@
|
|
|
1
1
|
# @littlebigbrain/client
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
TypeScript client for [little big brain](https://littlebigbrain.com), a search
|
|
4
|
+
platform for AI applications such as chatbots, search tools, and agents.
|
|
5
|
+
Load facts, query their relationships, and keep the data version behind an answer
|
|
6
|
+
so you can check it later.
|
|
7
|
+
|
|
8
|
+
The client has no runtime dependencies and includes generated request and response
|
|
9
|
+
types. It uses `fetch` and supports Node.js 18+, browsers, and edge workers.
|
|
10
|
+
Keep stack API keys on your server or local machine, outside browser bundles.
|
|
11
|
+
|
|
12
|
+
[Documentation](https://docs.littlebigbrain.com/sdks/typescript/) ·
|
|
13
|
+
[Quickstart](https://docs.littlebigbrain.com/start/quickstart/) ·
|
|
14
|
+
[Issues](https://github.com/littlebigbrains/lbb-typescript/issues)
|
|
15
|
+
|
|
16
|
+
## Install
|
|
4
17
|
|
|
5
18
|
```sh
|
|
6
19
|
npm install @littlebigbrain/client
|
|
7
20
|
```
|
|
8
21
|
|
|
9
|
-
##
|
|
22
|
+
## Load facts and run a query
|
|
23
|
+
|
|
24
|
+
Create a stack in the [console](https://cloud.littlebigbrain.com) and open
|
|
25
|
+
**Connect**. Copy its complete endpoint and a stack API key:
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
export LBB_URL="https://<your-complete-stack-host>"
|
|
29
|
+
export LBB_API_KEY="<your-stack-api-key>"
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
This example creates a graph named `quickstart` on its first write. It stores
|
|
33
|
+
three facts: a service writes to a database, and each has a label. The data uses
|
|
34
|
+
Resource Description Framework (RDF), where each line names a subject, a
|
|
35
|
+
relationship, and a value or another record. SPARQL is the query language for
|
|
36
|
+
those facts.
|
|
37
|
+
|
|
38
|
+
Save as `quickstart.mts`, then run `npx tsx quickstart.mts`:
|
|
10
39
|
|
|
11
40
|
```ts
|
|
12
41
|
import { LbbClient } from "@littlebigbrain/client";
|
|
13
42
|
|
|
14
43
|
const lbb = new LbbClient({
|
|
15
|
-
baseUrl:
|
|
16
|
-
apiKey: process.env.LBB_API_KEY
|
|
44
|
+
baseUrl: process.env.LBB_URL!,
|
|
45
|
+
apiKey: process.env.LBB_API_KEY!,
|
|
46
|
+
graph: "quickstart",
|
|
17
47
|
});
|
|
18
|
-
const graph = lbb.graph("main");
|
|
19
|
-
|
|
20
|
-
// 1. Write a fact.
|
|
21
|
-
await graph.facts.create(
|
|
22
|
-
{
|
|
23
|
-
triplets: [
|
|
24
|
-
{
|
|
25
|
-
source: { type: "CONCEPT", name: "policy-42" },
|
|
26
|
-
relation: "RELATED_TO",
|
|
27
|
-
target: { type: "CONCEPT", name: "seven-year retention" },
|
|
28
|
-
evidence: "Customer records are retained for seven years.",
|
|
29
|
-
},
|
|
30
|
-
],
|
|
31
|
-
},
|
|
32
|
-
{ idempotencyKey: "policy-42-v1" },
|
|
33
|
-
);
|
|
34
48
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
49
|
+
const facts = `
|
|
50
|
+
<https://example.org/auth-service> <https://example.org/writesTo> <https://example.org/user-db> .
|
|
51
|
+
<https://example.org/auth-service> <http://www.w3.org/2000/01/rdf-schema#label> "Auth Service" .
|
|
52
|
+
<https://example.org/user-db> <http://www.w3.org/2000/01/rdf-schema#label> "User Database" .
|
|
53
|
+
`;
|
|
38
54
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
55
|
+
const imported = await lbb.graph("quickstart").facts.importRdf(facts, {
|
|
56
|
+
format: "ntriples",
|
|
57
|
+
idempotencyKey: "sdk-quickstart-v1",
|
|
42
58
|
});
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
await
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
// …one record per line
|
|
58
|
-
],
|
|
59
|
-
{ idempotencyKey: "handbook-batch-1" },
|
|
59
|
+
const commitSeq = imported.committed_commit_seq;
|
|
60
|
+
if (commitSeq == null) throw new Error("The import did not return a commit sequence.");
|
|
61
|
+
|
|
62
|
+
const query = `
|
|
63
|
+
SELECT ?service ?database WHERE {
|
|
64
|
+
?s <https://example.org/writesTo> ?db .
|
|
65
|
+
?s <http://www.w3.org/2000/01/rdf-schema#label> ?service .
|
|
66
|
+
?db <http://www.w3.org/2000/01/rdf-schema#label> ?database .
|
|
67
|
+
} ORDER BY ?service ?database LIMIT 10
|
|
68
|
+
`;
|
|
69
|
+
|
|
70
|
+
const { rows } = await lbb.sparqlRows(
|
|
71
|
+
{ query },
|
|
72
|
+
{ consistency: "strong", minIndexedSeq: commitSeq },
|
|
60
73
|
);
|
|
74
|
+
|
|
75
|
+
for (const row of rows) console.log(`${row.service} -> ${row.database}`);
|
|
61
76
|
```
|
|
62
77
|
|
|
63
|
-
|
|
78
|
+
On a fresh graph, this prints:
|
|
64
79
|
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
idempotencyKey: "hubspot:portal-42:run-2026-07-29",
|
|
68
|
-
});
|
|
69
|
-
const completed = await lbb.waitForImportJob(accepted.job_id);
|
|
70
|
-
console.log(completed.state, completed.committed_commit_seq);
|
|
80
|
+
```text
|
|
81
|
+
Auth Service -> User Database
|
|
71
82
|
```
|
|
72
83
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
84
|
+
The query follows the stored relationship between the service and database.
|
|
85
|
+
`consistency: "strong"` makes the new facts available to this read without
|
|
86
|
+
waiting for a background index job. Reads default to eventual consistency, so
|
|
87
|
+
omit this option only when an earlier version is acceptable.
|
|
88
|
+
|
|
89
|
+
The idempotency key makes repeating the same import safe. Use a new key if you
|
|
90
|
+
change the data.
|
|
78
91
|
|
|
79
|
-
|
|
80
|
-
intermediate reconciliation and triggers it on the last document. Call
|
|
81
|
-
`graph.waitForPublished(result.finalSequence)` only when the caller needs the
|
|
82
|
-
immutable base itself to cover the import; strong reads need no waiter.
|
|
92
|
+
## Read the same version again
|
|
83
93
|
|
|
84
|
-
|
|
94
|
+
Run the query at the commit returned by the import:
|
|
85
95
|
|
|
86
96
|
```ts
|
|
87
|
-
const
|
|
88
|
-
query
|
|
89
|
-
|
|
97
|
+
const replay = await lbb.sparqlRows({
|
|
98
|
+
query,
|
|
99
|
+
as_of_commit_seq: commitSeq,
|
|
90
100
|
});
|
|
101
|
+
console.log(replay.rows);
|
|
91
102
|
```
|
|
92
103
|
|
|
93
|
-
|
|
104
|
+
Save the query, its options, and the commit sequence with any answer you need to
|
|
105
|
+
check later. See [history and replay](https://docs.littlebigbrain.com/guides/time-travel-audit/)
|
|
106
|
+
for retention and evidence handling.
|
|
94
107
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
108
|
+
## Next steps
|
|
109
|
+
|
|
110
|
+
- [Search by meaning](https://docs.littlebigbrain.com/guides/search-by-meaning/): choose which facts to embed and find records from a text description.
|
|
111
|
+
- [Load your own RDF](https://docs.littlebigbrain.com/guides/load-rdf/): import Turtle, N-Triples, N-Quads, or TriG.
|
|
112
|
+
- [Work with JSON records](https://docs.littlebigbrain.com/guides/without-rdf/): define a schema and write records without writing RDF.
|
|
113
|
+
- [Validate writes](https://docs.littlebigbrain.com/guides/sparql-and-shacl/): define constraints with the Shapes Constraint Language (SHACL).
|
|
100
114
|
|
|
101
|
-
|
|
115
|
+
The RDF and JSON guides use different write workflows. Choose one when creating
|
|
116
|
+
a graph; a graph first written through RDF import does not accept
|
|
117
|
+
`facts.create` or JSON record imports.
|
|
102
118
|
|
|
103
|
-
|
|
104
|
-
`waitForPublished(...)` is an optional, deadline-bounded maintenance poller for
|
|
105
|
-
workflows that want the immutable RDF base itself to cover a commit. Strong
|
|
106
|
-
SPARQL does not need it: acknowledged commits are queryable immediately from
|
|
107
|
-
the branch head's base-plus-delta lineage.
|
|
119
|
+
## Errors and retries
|
|
108
120
|
|
|
109
|
-
|
|
121
|
+
Failed HTTP requests throw `LbbError`, with a status, error code, message, and
|
|
122
|
+
request ID. Use `rawRequest()` when you also need response headers or timing.
|
|
110
123
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
published-generation maintenance automatically. Every generated shape is
|
|
116
|
-
available as `Schemas["TypeName"]`. Retired request-time JSON SHACL DTOs are
|
|
117
|
-
intentionally absent: publish RDF shapes with `schema.publish`, then read
|
|
118
|
-
`ontology.conformance`.
|
|
124
|
+
Safe reads and writes with an idempotency key retry rate limits, retryable server
|
|
125
|
+
errors, and network failures. Retries respect `Retry-After` and use a 60-second
|
|
126
|
+
budget by default. See the [client reference](https://docs.littlebigbrain.com/sdks/typescript/)
|
|
127
|
+
for timeout and retry options.
|
|
119
128
|
|
|
120
|
-
|
|
129
|
+
## Development
|
|
121
130
|
|
|
122
|
-
|
|
131
|
+
From a clone of this repository:
|
|
123
132
|
|
|
124
133
|
```sh
|
|
125
|
-
npm
|
|
126
|
-
npm run generate # regenerate types from contracts/openapi.json
|
|
134
|
+
npm ci
|
|
127
135
|
npm run typecheck
|
|
128
136
|
npm test
|
|
129
137
|
```
|
|
138
|
+
|
|
139
|
+
The request and response types are generated from the API contract. See
|
|
140
|
+
[CONTRIBUTING.md](CONTRIBUTING.md) for changes to generated types.
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
[Apache-2.0](LICENSE).
|
package/dist/client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DurableImportSource, ImportLine, LbbClientOptions, ListResponse, RawLbbResponse, ReadConsistencyOptions, RdfImportDocument, RdfImportManyResult, RdfImportOptions, Schemas, SearchConsistency, SparqlResults } from "./types.js";
|
|
2
2
|
import { type CallOptions, type RequestOptions } from "./transport.js";
|
|
3
|
-
import { EntityNamespace, GraphNamespace, OntologyNamespace, QueryNamespace, SchemaNamespace, SearchNamespace } from "./namespaces.js";
|
|
3
|
+
import { EntityNamespace, GraphNamespace, OntologyNamespace, QueryNamespace, SchemaNamespace, SearchNamespace, EvalsNamespace, EmbeddingsNamespace } from "./namespaces.js";
|
|
4
4
|
export { parseSparqlResults } from "./types.js";
|
|
5
5
|
export type { AttributeFilter, AttributeFilterOp, AttributeFilterValue, EntityAttributeFilterOptions, EntityPropertiesLine, DurableImportLine, DurableImportSource, FetchLike, FlatProperties, ImportLine, LbbClientOptions, LbbRequestEvent, LbbResponseEvent, LbbRetryEvent, LbbErrorPayload, ListResponse, RawLbbResponse, ReadConsistencyOptions, RdfImportDocument, RdfImportManyResult, RdfImportOptions, Schemas, SearchConsistency, SparqlResults, SparqlResultsJson, SparqlTerm, CommitRequest, CommitResponse, Entity, EntitySelector, GraphMetadata, GraphSummary, SchemaView, Snapshot, } from "./types.js";
|
|
6
6
|
export { LbbCapabilityError, LbbError } from "./transport.js";
|
|
@@ -34,6 +34,8 @@ export declare class LbbClient {
|
|
|
34
34
|
readonly schema: SchemaNamespace;
|
|
35
35
|
readonly ontology: OntologyNamespace;
|
|
36
36
|
readonly query: QueryNamespace;
|
|
37
|
+
readonly evals: EvalsNamespace;
|
|
38
|
+
readonly embeddings: EmbeddingsNamespace;
|
|
37
39
|
constructor(options: LbbClientOptions);
|
|
38
40
|
graph(name: string, opts?: {
|
|
39
41
|
branch?: string;
|
|
@@ -467,6 +469,9 @@ export declare class LbbClient {
|
|
|
467
469
|
}): Promise<Schemas["GraphMetadataResponse"]>;
|
|
468
470
|
/** Automatic publication lifecycle, available before the first generation exists. */
|
|
469
471
|
publicationStatus(): Promise<Schemas["PublicationStatusResponse"]>;
|
|
472
|
+
/** The managed models the platform uses per role (embedding, judge,
|
|
473
|
+
* rewriter): the operator's catalog, or the compiled defaults. */
|
|
474
|
+
managedModels(): Promise<Schemas["ManagedModelsResponse"]>;
|
|
470
475
|
/** Wait until background reconciliation folds `targetSeq` into the RDF base. */
|
|
471
476
|
waitForPublished(targetSeq: number, opts?: {
|
|
472
477
|
timeoutMs?: number;
|
package/dist/client.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { parseSparqlResults } from "./types.js";
|
|
2
2
|
import { bodyMarksTerminal, errorCodeFromBody, fullJitterBackoffMs, parseLbbError, parseResponseJson, retryAllowed, retryableStatus, retryDelayMs, sleep, } from "./transport.js";
|
|
3
3
|
import { LbbCapabilityError } from "./transport.js";
|
|
4
|
-
import { EntityNamespace, GraphNamespace, OntologyNamespace, QueryNamespace, SchemaNamespace, SearchNamespace, } from "./namespaces.js";
|
|
4
|
+
import { EntityNamespace, GraphNamespace, OntologyNamespace, QueryNamespace, SchemaNamespace, SearchNamespace, EvalsNamespace, EmbeddingsNamespace, } from "./namespaces.js";
|
|
5
5
|
export { parseSparqlResults } from "./types.js";
|
|
6
6
|
export { LbbCapabilityError, LbbError } from "./transport.js";
|
|
7
7
|
export { EntityNamespace, FactsNamespace, GraphNamespace, OntologyNamespace, QueryNamespace, SchemaNamespace, SearchNamespace, } from "./namespaces.js";
|
|
@@ -110,6 +110,8 @@ export class LbbClient {
|
|
|
110
110
|
schema;
|
|
111
111
|
ontology;
|
|
112
112
|
query;
|
|
113
|
+
evals;
|
|
114
|
+
embeddings;
|
|
113
115
|
constructor(options) {
|
|
114
116
|
const baseUrl = options.baseUrl?.trim();
|
|
115
117
|
if (!baseUrl) {
|
|
@@ -152,6 +154,8 @@ export class LbbClient {
|
|
|
152
154
|
this.schema = new SchemaNamespace(this);
|
|
153
155
|
this.ontology = new OntologyNamespace(this);
|
|
154
156
|
this.query = new QueryNamespace(this);
|
|
157
|
+
this.evals = new EvalsNamespace(this);
|
|
158
|
+
this.embeddings = new EmbeddingsNamespace(this);
|
|
155
159
|
}
|
|
156
160
|
graph(name, opts = {}) {
|
|
157
161
|
return new GraphNamespace(this.withScope({
|
|
@@ -1069,6 +1073,11 @@ export class LbbClient {
|
|
|
1069
1073
|
publicationStatus() {
|
|
1070
1074
|
return this.request("GET", "/v1/graph/publication-status");
|
|
1071
1075
|
}
|
|
1076
|
+
/** The managed models the platform uses per role (embedding, judge,
|
|
1077
|
+
* rewriter): the operator's catalog, or the compiled defaults. */
|
|
1078
|
+
managedModels() {
|
|
1079
|
+
return this.request("GET", "/v1/managed-models");
|
|
1080
|
+
}
|
|
1072
1081
|
/** Wait until background reconciliation folds `targetSeq` into the RDF base. */
|
|
1073
1082
|
async waitForPublished(targetSeq, opts = {}) {
|
|
1074
1083
|
if (!Number.isSafeInteger(targetSeq) || targetSeq < 0) {
|
package/dist/namespaces.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export declare class GraphNamespace {
|
|
|
9
9
|
readonly query: QueryNamespace;
|
|
10
10
|
readonly schema: SchemaNamespace;
|
|
11
11
|
readonly search: SearchNamespace;
|
|
12
|
+
readonly evals: EvalsNamespace;
|
|
13
|
+
readonly embeddings: EmbeddingsNamespace;
|
|
12
14
|
constructor(client: LbbClient);
|
|
13
15
|
branch(name: string): GraphNamespace;
|
|
14
16
|
/** Publication lifecycle for this graph/branch, including pre-first-publish state. */
|
|
@@ -51,7 +53,7 @@ export declare class FactsNamespace {
|
|
|
51
53
|
}
|
|
52
54
|
/**
|
|
53
55
|
* Relevance-label storage. The query surfaces this namespace once fronted were
|
|
54
|
-
* removed with their routes;
|
|
56
|
+
* removed with their routes; search by meaning is `embeddings.search`.
|
|
55
57
|
*/
|
|
56
58
|
export declare class SearchNamespace {
|
|
57
59
|
private readonly client;
|
|
@@ -86,6 +88,88 @@ export declare class EntityNamespace {
|
|
|
86
88
|
*/
|
|
87
89
|
filterByAttributes(opts: EntityAttributeFilterOptions): Promise<Schemas["SparqlSelectResponse"]>;
|
|
88
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Search: embeddings declared on classes of the graph. The platform keeps the
|
|
93
|
+
* vectors in step with the published graph; a search checks every hit against
|
|
94
|
+
* one graph snapshot.
|
|
95
|
+
*/
|
|
96
|
+
export declare class EmbeddingsNamespace {
|
|
97
|
+
private readonly client;
|
|
98
|
+
constructor(client: LbbClient);
|
|
99
|
+
/** Every embedding of the branch with its status. */
|
|
100
|
+
list(opts?: CallOptions): Promise<Schemas["EmbeddingListResponse"]>;
|
|
101
|
+
/** One embedding: serving and building version, backfill, lag, recall. */
|
|
102
|
+
get(name: string, opts?: CallOptions): Promise<Schemas["EmbeddingStatus"]>;
|
|
103
|
+
/**
|
|
104
|
+
* Declare or change the embedding of a class. Without `from` the server
|
|
105
|
+
* picks the fields (the label, frequent text, the names of linked
|
|
106
|
+
* entities). A new recipe builds as a new version while the old one serves.
|
|
107
|
+
*/
|
|
108
|
+
declare(body: Schemas["EmbeddingDeclareRequest"], opts?: CallOptions): Promise<Schemas["EmbeddingStatus"]>;
|
|
109
|
+
/**
|
|
110
|
+
* What a declaration would embed: the fields, every candidate fact of the
|
|
111
|
+
* class with its coverage and examples, and sample texts. Calls no model.
|
|
112
|
+
*/
|
|
113
|
+
preview(body: Schemas["EmbeddingPreviewRequest"], opts?: CallOptions): Promise<Schemas["EmbeddingPreviewResponse"]>;
|
|
114
|
+
/**
|
|
115
|
+
* Move every embedding of the graph to another model (one model per
|
|
116
|
+
* graph). Each builds a new version; the graph switches at once when
|
|
117
|
+
* every embedding has it ready, so a search never mixes two models.
|
|
118
|
+
*/
|
|
119
|
+
setModel(body: Schemas["EmbeddingModelRequest"], opts?: CallOptions): Promise<Schemas["EmbeddingListResponse"]>;
|
|
120
|
+
/** Run one bounded step of the embed job now. */
|
|
121
|
+
refresh(name: string, opts?: CallOptions): Promise<Schemas["EmbeddingRefreshResponse"]>;
|
|
122
|
+
/** Remove an embedding. */
|
|
123
|
+
delete(name: string, opts?: CallOptions): Promise<unknown>;
|
|
124
|
+
/**
|
|
125
|
+
* Search by meaning over every searchable class of the graph (or one
|
|
126
|
+
* `embedding`). `filter` lists the conditions every hit must meet:
|
|
127
|
+
* `{ class: iri }` (or a list; subclasses too) and
|
|
128
|
+
* `{ via: "calls", to: "payment-service", direction?: "in" }` (`to` an IRI
|
|
129
|
+
* or a name). Every hit carries its class and is checked against one
|
|
130
|
+
* graph snapshot; `include: ["text"]` returns the embedded text of each
|
|
131
|
+
* hit; `explain: true` plans without running.
|
|
132
|
+
*/
|
|
133
|
+
search(body: Schemas["SearchRequest"], opts?: CallOptions): Promise<Schemas["SearchResponse"]>;
|
|
134
|
+
}
|
|
135
|
+
/** Managed evals: traces, labels (thumbs up or down), goldens, and runs. */
|
|
136
|
+
export declare class EvalsNamespace {
|
|
137
|
+
private readonly client;
|
|
138
|
+
constructor(client: LbbClient);
|
|
139
|
+
/** Settings, golden counts, unlabeled traces, the latest run, and the score by commit. */
|
|
140
|
+
summary(opts?: CallOptions): Promise<Schemas["EvalSummaryResponse"]>;
|
|
141
|
+
/** Recent traces, newest first. */
|
|
142
|
+
traces(options?: {
|
|
143
|
+
limit?: number;
|
|
144
|
+
unlabeled?: boolean;
|
|
145
|
+
} & CallOptions): Promise<Schemas["EvalTraceListResponse"]>;
|
|
146
|
+
/** One trace: the request, its query, its results (one item per hit or
|
|
147
|
+
* row), and their labels. */
|
|
148
|
+
trace(id: string, opts?: CallOptions): Promise<Schemas["EvalTrace"]>;
|
|
149
|
+
/** Thumbs up or down on results of a trace: one result as `item` +
|
|
150
|
+
* `valid`, or several in `items`. The labels become the golden's ground
|
|
151
|
+
* truth. */
|
|
152
|
+
label(traceId: string, body: Schemas["EvalLabelRequest"], opts?: CallOptions): Promise<Schemas["EvalLabelResponse"]>;
|
|
153
|
+
/** Let the managed judge label the results of one trace, or of a batch of
|
|
154
|
+
* traces with unlabeled results. */
|
|
155
|
+
judge(options?: {
|
|
156
|
+
traceId?: string;
|
|
157
|
+
limit?: number;
|
|
158
|
+
} & CallOptions): Promise<Schemas["EvalJudgeResponse"]>;
|
|
159
|
+
goldens(opts?: CallOptions): Promise<Schemas["GoldenSuite"]>;
|
|
160
|
+
/** Freeze a query: every result it returns now is relevant. */
|
|
161
|
+
createGolden(body: Schemas["GoldenCreateRequest"], opts?: CallOptions): Promise<Schemas["GoldenResponse"]>;
|
|
162
|
+
/** Accept the results a golden returns now as its reference. */
|
|
163
|
+
acceptGolden(id: string, opts?: CallOptions & Pick<ReadConsistencyOptions, "consistency">): Promise<Schemas["GoldenResponse"]>;
|
|
164
|
+
deleteGolden(id: string, opts?: CallOptions): Promise<Schemas["GoldenDeleteResponse"]>;
|
|
165
|
+
/** Replay every golden at the current commit. */
|
|
166
|
+
run(opts?: CallOptions & Pick<ReadConsistencyOptions, "consistency">): Promise<Schemas["EvalRunResponse"]>;
|
|
167
|
+
results(options?: {
|
|
168
|
+
limit?: number;
|
|
169
|
+
} & CallOptions): Promise<Schemas["EvalResultsListResponse"]>;
|
|
170
|
+
settings(opts?: CallOptions): Promise<Schemas["EvalSettings"]>;
|
|
171
|
+
setSettings(body: Schemas["EvalSettings"], opts?: CallOptions): Promise<Schemas["EvalSettings"]>;
|
|
172
|
+
}
|
|
89
173
|
/** Active ontology/SHACL bundle metadata and atomic publication. */
|
|
90
174
|
export declare class SchemaNamespace {
|
|
91
175
|
private readonly client;
|
package/dist/namespaces.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { attributeFilter, firstPatternVariable, parseSparqlResults, } from "./types.js";
|
|
2
|
-
// SPARQL is the
|
|
3
|
-
//
|
|
2
|
+
// SPARQL is the query language. Search by meaning is `embeddings.search`
|
|
3
|
+
// (`POST /v1/search`); the older search, embedding, decode, groundability,
|
|
4
|
+
// and analytics operations were removed with their routes.
|
|
4
5
|
/** A5: fold read-consistency options into a request body's `consistency` /
|
|
5
6
|
* `min_indexed_seq` fields; a per-call value wins over the client default. */
|
|
6
7
|
function withReadConsistency(client, body, opts) {
|
|
@@ -23,6 +24,8 @@ export class GraphNamespace {
|
|
|
23
24
|
query;
|
|
24
25
|
schema;
|
|
25
26
|
search;
|
|
27
|
+
evals;
|
|
28
|
+
embeddings;
|
|
26
29
|
constructor(client) {
|
|
27
30
|
this.client = client;
|
|
28
31
|
this.facts = new FactsNamespace(client);
|
|
@@ -31,6 +34,8 @@ export class GraphNamespace {
|
|
|
31
34
|
this.query = client.query;
|
|
32
35
|
this.schema = client.schema;
|
|
33
36
|
this.search = client.search;
|
|
37
|
+
this.evals = client.evals;
|
|
38
|
+
this.embeddings = client.embeddings;
|
|
34
39
|
}
|
|
35
40
|
branch(name) {
|
|
36
41
|
return new GraphNamespace(this.client.withScope({ branch: name }));
|
|
@@ -135,7 +140,7 @@ export class FactsNamespace {
|
|
|
135
140
|
}
|
|
136
141
|
/**
|
|
137
142
|
* Relevance-label storage. The query surfaces this namespace once fronted were
|
|
138
|
-
* removed with their routes;
|
|
143
|
+
* removed with their routes; search by meaning is `embeddings.search`.
|
|
139
144
|
*/
|
|
140
145
|
export class SearchNamespace {
|
|
141
146
|
client;
|
|
@@ -199,6 +204,173 @@ export class EntityNamespace {
|
|
|
199
204
|
});
|
|
200
205
|
}
|
|
201
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* Search: embeddings declared on classes of the graph. The platform keeps the
|
|
209
|
+
* vectors in step with the published graph; a search checks every hit against
|
|
210
|
+
* one graph snapshot.
|
|
211
|
+
*/
|
|
212
|
+
export class EmbeddingsNamespace {
|
|
213
|
+
client;
|
|
214
|
+
constructor(client) {
|
|
215
|
+
this.client = client;
|
|
216
|
+
}
|
|
217
|
+
/** Every embedding of the branch with its status. */
|
|
218
|
+
list(opts = {}) {
|
|
219
|
+
return this.client.request("GET", "/v1/embeddings", opts);
|
|
220
|
+
}
|
|
221
|
+
/** One embedding: serving and building version, backfill, lag, recall. */
|
|
222
|
+
get(name, opts = {}) {
|
|
223
|
+
return this.client.request("GET", "/v1/embeddings", {
|
|
224
|
+
...opts,
|
|
225
|
+
query: { name },
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Declare or change the embedding of a class. Without `from` the server
|
|
230
|
+
* picks the fields (the label, frequent text, the names of linked
|
|
231
|
+
* entities). A new recipe builds as a new version while the old one serves.
|
|
232
|
+
*/
|
|
233
|
+
declare(body, opts = {}) {
|
|
234
|
+
return this.client.request("PUT", "/v1/embeddings", { ...opts, body });
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* What a declaration would embed: the fields, every candidate fact of the
|
|
238
|
+
* class with its coverage and examples, and sample texts. Calls no model.
|
|
239
|
+
*/
|
|
240
|
+
preview(body, opts = {}) {
|
|
241
|
+
return this.client.request("POST", "/v1/embeddings/preview", {
|
|
242
|
+
...opts,
|
|
243
|
+
body,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Move every embedding of the graph to another model (one model per
|
|
248
|
+
* graph). Each builds a new version; the graph switches at once when
|
|
249
|
+
* every embedding has it ready, so a search never mixes two models.
|
|
250
|
+
*/
|
|
251
|
+
setModel(body, opts = {}) {
|
|
252
|
+
return this.client.request("PUT", "/v1/embeddings/model", {
|
|
253
|
+
...opts,
|
|
254
|
+
body,
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
/** Run one bounded step of the embed job now. */
|
|
258
|
+
refresh(name, opts = {}) {
|
|
259
|
+
return this.client.request("POST", "/v1/embeddings/refresh", {
|
|
260
|
+
...opts,
|
|
261
|
+
query: { name },
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
/** Remove an embedding. */
|
|
265
|
+
delete(name, opts = {}) {
|
|
266
|
+
return this.client.request("DELETE", "/v1/embeddings", {
|
|
267
|
+
...opts,
|
|
268
|
+
query: { name, confirm: name },
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Search by meaning over every searchable class of the graph (or one
|
|
273
|
+
* `embedding`). `filter` lists the conditions every hit must meet:
|
|
274
|
+
* `{ class: iri }` (or a list; subclasses too) and
|
|
275
|
+
* `{ via: "calls", to: "payment-service", direction?: "in" }` (`to` an IRI
|
|
276
|
+
* or a name). Every hit carries its class and is checked against one
|
|
277
|
+
* graph snapshot; `include: ["text"]` returns the embedded text of each
|
|
278
|
+
* hit; `explain: true` plans without running.
|
|
279
|
+
*/
|
|
280
|
+
search(body, opts = {}) {
|
|
281
|
+
return this.client.request("POST", "/v1/search", {
|
|
282
|
+
...opts,
|
|
283
|
+
retry: opts.retry ?? true,
|
|
284
|
+
body,
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
/** Managed evals: traces, labels (thumbs up or down), goldens, and runs. */
|
|
289
|
+
export class EvalsNamespace {
|
|
290
|
+
client;
|
|
291
|
+
constructor(client) {
|
|
292
|
+
this.client = client;
|
|
293
|
+
}
|
|
294
|
+
/** Settings, golden counts, unlabeled traces, the latest run, and the score by commit. */
|
|
295
|
+
summary(opts = {}) {
|
|
296
|
+
return this.client.request("GET", "/v1/evals", opts);
|
|
297
|
+
}
|
|
298
|
+
/** Recent traces, newest first. */
|
|
299
|
+
traces(options = {}) {
|
|
300
|
+
const { limit, unlabeled, ...opts } = options;
|
|
301
|
+
return this.client.request("GET", "/v1/evals/traces", {
|
|
302
|
+
...opts,
|
|
303
|
+
query: { limit, unlabeled: unlabeled ? "true" : undefined },
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
/** One trace: the request, its query, its results (one item per hit or
|
|
307
|
+
* row), and their labels. */
|
|
308
|
+
trace(id, opts = {}) {
|
|
309
|
+
return this.client.request("GET", "/v1/evals/trace", {
|
|
310
|
+
...opts,
|
|
311
|
+
query: { id },
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
/** Thumbs up or down on results of a trace: one result as `item` +
|
|
315
|
+
* `valid`, or several in `items`. The labels become the golden's ground
|
|
316
|
+
* truth. */
|
|
317
|
+
label(traceId, body, opts = {}) {
|
|
318
|
+
return this.client.request("POST", "/v1/evals/label", {
|
|
319
|
+
...opts,
|
|
320
|
+
query: { trace: traceId },
|
|
321
|
+
body,
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
/** Let the managed judge label the results of one trace, or of a batch of
|
|
325
|
+
* traces with unlabeled results. */
|
|
326
|
+
judge(options = {}) {
|
|
327
|
+
const { traceId, limit, ...opts } = options;
|
|
328
|
+
return this.client.request("POST", "/v1/evals/judge", {
|
|
329
|
+
...opts,
|
|
330
|
+
query: { trace: traceId, limit },
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
goldens(opts = {}) {
|
|
334
|
+
return this.client.request("GET", "/v1/evals/goldens", opts);
|
|
335
|
+
}
|
|
336
|
+
/** Freeze a query: every result it returns now is relevant. */
|
|
337
|
+
createGolden(body, opts = {}) {
|
|
338
|
+
return this.client.request("POST", "/v1/evals/goldens", { ...opts, body });
|
|
339
|
+
}
|
|
340
|
+
/** Accept the results a golden returns now as its reference. */
|
|
341
|
+
acceptGolden(id, opts = {}) {
|
|
342
|
+
return this.client.request("POST", "/v1/evals/goldens/accept", {
|
|
343
|
+
...opts,
|
|
344
|
+
query: { id, consistency: opts.consistency },
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
deleteGolden(id, opts = {}) {
|
|
348
|
+
return this.client.request("DELETE", "/v1/evals/goldens", {
|
|
349
|
+
...opts,
|
|
350
|
+
query: { id },
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
/** Replay every golden at the current commit. */
|
|
354
|
+
run(opts = {}) {
|
|
355
|
+
return this.client.request("POST", "/v1/evals/run", {
|
|
356
|
+
...opts,
|
|
357
|
+
query: { consistency: opts.consistency },
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
results(options = {}) {
|
|
361
|
+
const { limit, ...opts } = options;
|
|
362
|
+
return this.client.request("GET", "/v1/evals/results", {
|
|
363
|
+
...opts,
|
|
364
|
+
query: { limit },
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
settings(opts = {}) {
|
|
368
|
+
return this.client.request("GET", "/v1/evals/settings", opts);
|
|
369
|
+
}
|
|
370
|
+
setSettings(body, opts = {}) {
|
|
371
|
+
return this.client.request("PUT", "/v1/evals/settings", { ...opts, body });
|
|
372
|
+
}
|
|
373
|
+
}
|
|
202
374
|
/** Active ontology/SHACL bundle metadata and atomic publication. */
|
|
203
375
|
export class SchemaNamespace {
|
|
204
376
|
client;
|