Skip to content

Commit

Permalink
Merge pull request #2 from upstash/change-stat-to-info
Browse files Browse the repository at this point in the history
Change stat to info
  • Loading branch information
ogzhanolguncu authored Jan 30, 2024
2 parents 3c462ad + 014e61b commit 12e029e
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,12 @@ await index.delete("id-to-delete");
await index.delete(["id-1", "id-2", "id-3"]);
```

### Stats
### Info

To get statistics of your index, you can use the client like so:

```typescript
await index.stats(["id-1", "id-2", "id-3"]);
await index.info(["id-1", "id-2", "id-3"]);
```

### Reset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { afterAll, describe, expect, test } from "bun:test";
import { UpsertCommand } from "@commands/index";
import { newHttpClient, randomFloat, randomID, resetIndexes } from "@utils/test-utils";
import { sleep } from "bun";
import { StatsCommand } from ".";
import { InfoCommand } from ".";

const client = newHttpClient();

describe("STATS", () => {
describe("INFO", () => {
afterAll(async () => await resetIndexes());

test("should return vectorCount successfully", async () => {
Expand All @@ -19,7 +19,7 @@ describe("STATS", () => {
const payloads = randomizedData.map((data) => new UpsertCommand(data).exec(client));
await Promise.all(payloads);
await sleep(2000);
const res = await new StatsCommand().exec(client);
const res = await new InfoCommand().exec(client);
expect(res.vectorCount).toBeGreaterThanOrEqual(vectorCount);
});
});
15 changes: 15 additions & 0 deletions src/commands/client/info/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Command } from "@commands/command";

export type InfoResult = {
vectorCount: number;
pendingVectorCount: number;
indexSize: number;
dimension: number;
similarityFunction: "COSINE" | "EUCLIDEAN" | "DOT_PRODUCT";
};

export class InfoCommand extends Command<InfoResult> {
constructor() {
super([], "info");
}
}
13 changes: 0 additions & 13 deletions src/commands/client/stats/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/commands/command.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { UpstashError } from "@error/index";
import { Requester } from "@http";

const ENDPOINTS = ["upsert", "query", "delete", "fetch", "reset", "range", "stats"] as const;
const ENDPOINTS = ["upsert", "query", "delete", "fetch", "reset", "range", "info"] as const;

export type EndpointVariants = (typeof ENDPOINTS)[number];
/**
Expand Down
2 changes: 1 addition & 1 deletion src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ export * from "./client/query";
export * from "./client/upsert";
export * from "./client/reset";
export * from "./client/range";
export * from "./client/stats";
export * from "./client/info";
2 changes: 1 addition & 1 deletion src/commands/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export { type Vector } from "./client/types";
export { type RangeResult } from "./client/range/index";
export { type FetchResult } from "./client/fetch/index";
export { type QueryResult } from "./client/query/index";
export { type StatsResult } from "./client/stats/index";
export { type InfoResult } from "./client/info/index";
12 changes: 6 additions & 6 deletions src/vector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
UpsertCommand,
} from "@commands/client";
import { Requester } from "@http";
import { StatsCommand } from "./commands";
import { InfoCommand } from "./commands";

export type CommandArgs<TCommand extends new (_args: any) => any> =
ConstructorParameters<TCommand>[0];
Expand Down Expand Up @@ -154,15 +154,15 @@ export class Index {
new RangeCommand<TMetadata>(args).exec(this.client);

/**
* Retrieves stats from the index.
* Retrieves info from the index.
*
* @example
* ```js
* const statResults = await index.stats();
* console.log(statResults); // Outputs the result of the stats operation
* const infoResults = await index.info();
* console.log(infoResults); // Outputs the result of the info operation
* ```
*
* @returns {Promise<RangeReturnResponse<TMetadata>>} A promise that resolves with the response containing the vectorCount, pendingVectorCount, indexSize after the command is executed.
* @returns {Promise<InfoResult>} A promise that resolves with the response containing the vectorCount, pendingVectorCount, indexSize, dimension count and similarity algorithm after the command is executed.
*/
stats = () => new StatsCommand().exec(this.client);
info = () => new InfoCommand().exec(this.client);
}
2 changes: 0 additions & 2 deletions tsup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ export default defineConfig({
format: ["cjs", "esm"],
sourcemap: false,
clean: true,
bundle: true,
dts: true,
minify: true,
treeshake: true,
});

0 comments on commit 12e029e

Please sign in to comment.