@turbopuffer/turbopuffer
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -79,7 +79,24 @@ /** | ||
/** | ||
* List all your namespaces. | ||
* See: https://turbopuffer.com/docs/reference/namespaces | ||
*/ | ||
namespaces({ cursor, page_size, }: { | ||
cursor?: string; | ||
page_size?: number; | ||
}): Promise<NamespacesListResult>; | ||
/** | ||
* Creates a namespace object to operate on. Operations | ||
* should be called on the Namespace object itself. | ||
*/ | ||
namespace(id: string): Namespace; | ||
} | ||
export declare class Namespace { | ||
private client; | ||
id: string; | ||
constructor(client: Turbopuffer, id: string); | ||
/** | ||
* Creates, updates, or deletes vectors. | ||
* See: https://turbopuffer.com/docs/reference/upsert | ||
*/ | ||
upsert({ namespace, vectors, distance_metric, }: { | ||
namespace: string; | ||
upsert({ vectors, distance_metric, }: { | ||
vectors: Vector[]; | ||
@@ -92,4 +109,3 @@ distance_metric: DistanceMetric; | ||
*/ | ||
query({ namespace, ...params }: { | ||
namespace: string; | ||
query({ ...params }: { | ||
vector?: number[]; | ||
@@ -106,4 +122,3 @@ distance_metric?: DistanceMetric; | ||
*/ | ||
export({ namespace, cursor, }: { | ||
namespace: string; | ||
export({ cursor, }: { | ||
cursor?: string; | ||
@@ -117,16 +132,8 @@ }): Promise<{ | ||
*/ | ||
approxNumVectors(namespace: string): Promise<number>; | ||
approxNumVectors({}: {}): Promise<number>; | ||
/** | ||
* List all your namespaces. | ||
* See: https://turbopuffer.com/docs/reference/namespaces | ||
*/ | ||
listNamespaces({ cursor, page_size, }: { | ||
cursor?: string; | ||
page_size?: number; | ||
}): Promise<NamespacesListResult>; | ||
/** | ||
* Delete a namespace fully (all data). | ||
* See: https://turbopuffer.com/docs/reference/delete-namespace | ||
*/ | ||
deleteNamespace(namespace: string): Promise<void>; | ||
delete(): Promise<void>; | ||
/** | ||
@@ -136,4 +143,3 @@ * Evaluates the recall performance of ANN queries in a namespace. | ||
*/ | ||
recall({ namespace, num, top_k, filters, queries, }: { | ||
namespace: string; | ||
recall({ num, top_k, filters, queries, }: { | ||
num?: number; | ||
@@ -140,0 +146,0 @@ top_k?: number; |
@@ -23,3 +23,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Turbopuffer = exports.TurbopufferError = void 0; | ||
exports.Namespace = exports.Turbopuffer = exports.TurbopufferError = void 0; | ||
const pako_1 = __importDefault(require("pako")); | ||
@@ -36,3 +36,3 @@ require("isomorphic-fetch"); | ||
exports.TurbopufferError = TurbopufferError; | ||
/* Client */ | ||
/* Base Client */ | ||
class Turbopuffer { | ||
@@ -102,9 +102,37 @@ constructor({ apiKey, baseUrl = "https://api.turbopuffer.com", }) { | ||
/** | ||
* List all your namespaces. | ||
* See: https://turbopuffer.com/docs/reference/namespaces | ||
*/ | ||
async namespaces({ cursor, page_size, }) { | ||
return (await this.doRequest({ | ||
method: "GET", | ||
path: "/v1/vectors", | ||
query: { | ||
cursor, | ||
page_size: page_size ? page_size.toString() : undefined, | ||
}, | ||
})).body; | ||
} | ||
/** | ||
* Creates a namespace object to operate on. Operations | ||
* should be called on the Namespace object itself. | ||
*/ | ||
namespace(id) { | ||
return new Namespace(this, id); | ||
} | ||
} | ||
exports.Turbopuffer = Turbopuffer; | ||
class Namespace { | ||
constructor(client, id) { | ||
this.client = client; | ||
this.id = id; | ||
} | ||
/** | ||
* Creates, updates, or deletes vectors. | ||
* See: https://turbopuffer.com/docs/reference/upsert | ||
*/ | ||
async upsert({ namespace, vectors, distance_metric, }) { | ||
await this.doRequest({ | ||
async upsert({ vectors, distance_metric, }) { | ||
await this.client.doRequest({ | ||
method: "POST", | ||
path: `/v1/vectors/${namespace}`, | ||
path: `/v1/vectors/${this.id}`, | ||
compress: vectors.length > 10, | ||
@@ -122,6 +150,6 @@ body: { | ||
async query(_a) { | ||
var { namespace } = _a, params = __rest(_a, ["namespace"]); | ||
return (await this.doRequest({ | ||
var params = __rest(_a, []); | ||
return (await this.client.doRequest({ | ||
method: "POST", | ||
path: `/v1/vectors/${namespace}/query`, | ||
path: `/v1/vectors/${this.id}/query`, | ||
body: params, | ||
@@ -134,6 +162,6 @@ })).body; | ||
*/ | ||
async export({ namespace, cursor, }) { | ||
let response = await this.doRequest({ | ||
async export({ cursor, }) { | ||
let response = await this.client.doRequest({ | ||
method: "GET", | ||
path: `/v1/vectors/${namespace}`, | ||
path: `/v1/vectors/${this.id}`, | ||
query: { cursor }, | ||
@@ -149,6 +177,6 @@ }); | ||
*/ | ||
async approxNumVectors(namespace) { | ||
let response = await this.doRequest({ | ||
async approxNumVectors({}) { | ||
let response = await this.client.doRequest({ | ||
method: "HEAD", | ||
path: `/v1/vectors/${namespace}`, | ||
path: `/v1/vectors/${this.id}`, | ||
}); | ||
@@ -159,23 +187,9 @@ let num = response.headers.get("X-turbopuffer-Approx-Num-Vectors"); | ||
/** | ||
* List all your namespaces. | ||
* See: https://turbopuffer.com/docs/reference/namespaces | ||
*/ | ||
async listNamespaces({ cursor, page_size, }) { | ||
return (await this.doRequest({ | ||
method: "GET", | ||
path: "/v1/vectors", | ||
query: { | ||
cursor, | ||
page_size: page_size ? page_size.toString() : undefined, | ||
}, | ||
})).body; | ||
} | ||
/** | ||
* Delete a namespace fully (all data). | ||
* See: https://turbopuffer.com/docs/reference/delete-namespace | ||
*/ | ||
async deleteNamespace(namespace) { | ||
await this.doRequest({ | ||
async delete() { | ||
await this.client.doRequest({ | ||
method: "DELETE", | ||
path: `/v1/vectors/${namespace}`, | ||
path: `/v1/vectors/${this.id}`, | ||
}); | ||
@@ -187,6 +201,6 @@ } | ||
*/ | ||
async recall({ namespace, num, top_k, filters, queries, }) { | ||
return (await this.doRequest({ | ||
async recall({ num, top_k, filters, queries, }) { | ||
return (await this.client.doRequest({ | ||
method: "POST", | ||
path: `/v1/vectors/${namespace}/_debug/recall`, | ||
path: `/v1/vectors/${this.id}/_debug/recall`, | ||
compress: queries && queries.length > 10, | ||
@@ -204,3 +218,3 @@ body: { | ||
} | ||
exports.Turbopuffer = Turbopuffer; | ||
exports.Namespace = Namespace; | ||
// Unused atm. | ||
@@ -207,0 +221,0 @@ function toColumnar(vectors) { |
{ | ||
"name": "@turbopuffer/turbopuffer", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Official Typescript API client library for turbopuffer.com", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -13,9 +13,11 @@ The **official TypeScript SDK** for Turbopuffer. | ||
// Make a new client | ||
const client = new Turbopuffer({ | ||
const tpuf = new Turbopuffer({ | ||
apiKey: process.env.TURBOPUFFER_API_KEY as string, | ||
}); | ||
// Upsert some vectors to a namespace | ||
await client.upsert({ | ||
"my-cool-namespace", | ||
// Instantiate an object to work with a namespace | ||
const ns = tpuf.namespace("my-cool-namespace"); | ||
// Upsert some vectors | ||
await ns.upsert({ | ||
vectors: [ | ||
@@ -42,5 +44,4 @@ { | ||
// Query the namespace | ||
let results = await client.query({ | ||
namespace, | ||
// Query | ||
let results = await ns.query({ | ||
vector: [1, 1], | ||
@@ -52,1 +53,7 @@ filters: { | ||
``` | ||
To publish a new version, | ||
```bash | ||
npm publish --access public | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24895
398
57