Skip to content

Commit

Permalink
Pass generics to commands and fix typos in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ogzhanolguncu committed Jan 18, 2024
1 parent ae4432c commit b052b85
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ UPSTASH_VECTOR_REST_TOKEN="your_rest_token"
When these environment variables are set, the client constructor does not require any additional arguments.

```typescript
import { fromEnv } from "@upstash/vector";
import { Index } from "@upstash/vector";

const index = new Index();
```
Expand Down Expand Up @@ -97,7 +97,7 @@ if (results[0].metadata) {
// Since we passed the Metadata type parameter above,
// we can interact with metadata fields without having to
// do any typecasting.
const { title, genre, category } = movie.metadata;
const { title, genre, category } = results[0].metadata;
console.log(`The best match in fantasy was ${title}`)
}
```
Expand Down Expand Up @@ -238,6 +238,14 @@ To get statistics of your index, you can use the client like so:
await index.stats(["id-1", "id-2", "id-3"]);
```

### Reset

To delete everything related with that index:

```typescript
await index.reset();
```

## Contributing

## Preparing the environment
Expand Down
15 changes: 10 additions & 5 deletions src/vector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export class Index {
* @param id - List of ids or single id
* @returns A promise that resolves when the request to delete the index is completed.
*/
delete = (args: CommandArgs<typeof DeleteCommand>) => new DeleteCommand(args).exec(this.client);
delete = (args: CommandArgs<typeof DeleteCommand>) =>
new DeleteCommand(args).exec(this.client);

/**
* Queries an index with specified parameters.
Expand All @@ -64,7 +65,8 @@ export class Index {
*
* @returns A promise that resolves with an array of query result objects when the request to query the index is completed.
*/
query = (args: CommandArgs<typeof QueryCommand>) => new QueryCommand(args).exec(this.client);
query = <TMetadata>(args: CommandArgs<typeof QueryCommand>) =>
new QueryCommand<TMetadata>(args).exec(this.client);

/**
* Upserts (Updates and Inserts) specific items into the index.
Expand All @@ -88,7 +90,8 @@ export class Index {
*
* @returns {string} A promise that resolves with the result of the upsert operation after the command is executed.
*/
upsert = (args: CommandArgs<typeof UpsertCommand>) => new UpsertCommand(args).exec(this.client);
upsert = (args: CommandArgs<typeof UpsertCommand>) =>
new UpsertCommand(args).exec(this.client);

/**
* It's used for retrieving specific items from the index, optionally including
Expand All @@ -110,7 +113,8 @@ export class Index {
*
* @returns {Promise<FetchReturnResponse<TMetadata>[]>} A promise that resolves with an array of fetched items or null if not found, after the command is executed.
*/
fetch = (...args: CommandArgs<typeof FetchCommand>) => new FetchCommand(args).exec(this.client);
fetch = <TMetadata>(...args: CommandArgs<typeof FetchCommand>) =>
new FetchCommand<TMetadata>(args).exec(this.client);

/**
* It's used for wiping an entire index.
Expand Down Expand Up @@ -148,7 +152,8 @@ export class Index {
*
* @returns {Promise<RangeReturnResponse<TMetadata>>} A promise that resolves with the response containing the next cursor and an array of vectors, after the command is executed.
*/
range = (args: CommandArgs<typeof RangeCommand>) => new RangeCommand(args).exec(this.client);
range = <TMetadata>(args: CommandArgs<typeof RangeCommand>) =>
new RangeCommand<TMetadata>(args).exec(this.client);

/**
* Retrieves stats from the index.
Expand Down

0 comments on commit b052b85

Please sign in to comment.