Skip to content

Commit

Permalink
refactor: mvi list indexes response to contain index info detail (#1016)
Browse files Browse the repository at this point in the history
Previously a list indexes success response only contained a list of
index names. We refactor this to contain a list of `VectorIndexInfo`
objects, each of which can contain encapsulate many details. To start
we only include the index name.

We update the integration tests and indexes along with this.
  • Loading branch information
malandis authored Nov 8, 2023
1 parent 05915cd commit 0e7533a
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 11 deletions.
2 changes: 2 additions & 0 deletions packages/client-sdk-nodejs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ import {
IMomentoCache,
SubscribeCallOptions,
CacheInfo,
VectorIndexInfo,
CollectionTtl,
ItemType,
SortedSetOrder,
Expand Down Expand Up @@ -218,6 +219,7 @@ export {
CacheClient,
SimpleCacheClient,
CacheInfo,
VectorIndexInfo,
// Credentials / Auth
CredentialProvider,
StringMomentoTokenProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
InvalidArgumentError,
MomentoLogger,
VectorIndexConfiguration,
VectorIndexInfo,
} from '..';
import {version} from '../../package.json';
import {IdleGrpcClientWrapper} from './grpc/idle-grpc-client-wrapper';
Expand Down Expand Up @@ -148,9 +149,11 @@ export class VectorIndexControlClient implements IVectorIndexControlClient {
new ListVectorIndexes.Error(cacheServiceErrorMapper(err))
);
} else {
// TODO: um, what?
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call
const indexes = resp.index_names;
const indexes = resp.index_names.map((name: string) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
return new VectorIndexInfo(name);
});
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
resolve(new ListVectorIndexes.Success(indexes));
}
Expand Down
2 changes: 2 additions & 0 deletions packages/client-sdk-web/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import {
IMomentoCache,
SubscribeCallOptions,
CacheInfo,
VectorIndexInfo,
CollectionTtl,
ItemType,
SortedSetOrder,
Expand Down Expand Up @@ -172,6 +173,7 @@ export {
VectorIndexConfiguration,
VectorIndexConfigurations,
CacheInfo,
VectorIndexInfo,
CredentialProvider,
StringMomentoTokenProvider,
EnvMomentoTokenProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
InvalidArgumentError,
MomentoLogger,
VectorIndexConfiguration,
VectorIndexInfo,
} from '..';
import {Request, StatusCode, UnaryResponse} from 'grpc-web';
import {
Expand Down Expand Up @@ -141,7 +142,13 @@ export class VectorIndexControlClient<
if (err) {
resolve(new ListVectorIndexes.Error(cacheServiceErrorMapper(err)));
} else {
const indexes = resp.getIndexNamesList();
const indexes: VectorIndexInfo[] = resp
.getIndexNamesList()
.map((name: string) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
return new VectorIndexInfo(name);
});
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
resolve(new ListVectorIndexes.Success(indexes));
}
}
Expand Down
5 changes: 3 additions & 2 deletions packages/common-integration-tests/src/vector-control-plane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ export function runVectorControlPlaneTest(vectorClient: IVectorIndexClient) {
expect(listResponse).toBeInstanceOf(ListVectorIndexes.Success);
}, `expected SUCCESS but got ${listResponse.toString()}`);
if (listResponse instanceof ListVectorIndexes.Success) {
const caches = listResponse.getIndexNames();
expect(caches.includes(indexName)).toBeTruthy();
const indexes = listResponse.getIndexes();
const indexNames = indexes.map(indexInfo => indexInfo.getName());
expect(indexNames.includes(indexName)).toBeTruthy();
}
}
);
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export * as leaderboard from './messages/responses/leaderboard';
export * from './messages/responses/leaderboard';

import {CacheInfo} from './messages/cache-info';
export {VectorIndexInfo} from './messages/vector-index-info';
import {
SubscribeCallOptions,
CollectionTtl,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {SdkError} from '../../../errors';
import {VectorIndexInfo} from '../../vector-index-info';
import {ResponseBase, ResponseError, ResponseSuccess} from '../response-base';

/**
Expand All @@ -23,22 +24,23 @@ import {ResponseBase, ResponseError, ResponseSuccess} from '../response-base';
export abstract class Response extends ResponseBase {}

class _Success extends Response {
private readonly indexNames: string[];
constructor(indexNames: string[]) {
private readonly indexes: VectorIndexInfo[];
constructor(indexes: VectorIndexInfo[]) {
super();
this.indexNames = indexNames;
this.indexes = indexes;
}

/**
* An array of index names.
* @returns {string[]}
*/
public getIndexNames() {
return this.indexNames;
public getIndexes() {
return this.indexes;
}

public override toString() {
return super.toString() + ': ' + this.indexNames.join(', ');
const indexes = this.indexes.map(indexInfo => indexInfo.getName());
return super.toString() + ': ' + indexes.join(', ');
}
}

Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/messages/vector-index-info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export class VectorIndexInfo {
private readonly name: string;

constructor(name: string) {
this.name = name;
}

public getName() {
return this.name;
}
}

0 comments on commit 0e7533a

Please sign in to comment.