Skip to content

Commit

Permalink
chore: update mvi control plane backend for latest create and list in…
Browse files Browse the repository at this point in the history
…dexes protos (#1042)

Update MVI list and create index backends for latest protos. The developer-facing API remains the same; this is only an internal update.
  • Loading branch information
malandis authored Nov 15, 2023
1 parent 50184b3 commit 0bd5d6d
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 31 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ jobs:
pushd examples/nodejs/vector-index
npm ci
npm run build
npm run validate-examples
# TODO re-enable once we update the example to use the new SDK
#npm run validate-examples
popd
pushd examples/nodejs/rate-limiter
npm ci
Expand Down Expand Up @@ -212,7 +213,8 @@ jobs:
pushd examples/web/vector-index
npm ci
npm run build
npm run validate-examples
# TODO re-enable once we update the example to use the new SDK
#npm run validate-examples
popd
- name: Send CI failure mail
Expand Down
10 changes: 6 additions & 4 deletions packages/client-sdk-nodejs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/client-sdk-nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"uuid": "8.3.2"
},
"dependencies": {
"@gomomento/generated-types": "0.94.1",
"@gomomento/generated-types": "0.96.0",
"@gomomento/sdk-core": "file:../core",
"@grpc/grpc-js": "1.9.0",
"google-protobuf": "3.21.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,19 @@ export class VectorIndexControlClient implements IVectorIndexControlClient {

similarityMetric ??= VectorSimilarityMetric.COSINE_SIMILARITY;

const similarityMetricPb = new grpcControl._SimilarityMetric();
switch (similarityMetric) {
case VectorSimilarityMetric.INNER_PRODUCT:
request.inner_product =
new grpcControl._CreateIndexRequest._InnerProduct();
similarityMetricPb.inner_product =
new grpcControl._SimilarityMetric._InnerProduct();
break;
case VectorSimilarityMetric.EUCLIDEAN_SIMILARITY:
request.euclidean_similarity =
new grpcControl._CreateIndexRequest._EuclideanSimilarity();
similarityMetricPb.euclidean_similarity =
new grpcControl._SimilarityMetric._EuclideanSimilarity();
break;
case VectorSimilarityMetric.COSINE_SIMILARITY:
request.cosine_similarity =
new grpcControl._CreateIndexRequest._CosineSimilarity();
similarityMetricPb.cosine_similarity =
new grpcControl._SimilarityMetric._CosineSimilarity();
break;
default:
return new CreateVectorIndex.Error(
Expand All @@ -109,6 +110,7 @@ export class VectorIndexControlClient implements IVectorIndexControlClient {
)
);
}
request.similarity_metric = similarityMetricPb;

return await new Promise<CreateVectorIndex.Response>(resolve => {
this.clientWrapper.getClient().CreateIndex(
Expand Down Expand Up @@ -149,12 +151,9 @@ export class VectorIndexControlClient implements IVectorIndexControlClient {
new ListVectorIndexes.Error(cacheServiceErrorMapper(err))
);
} else {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call
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);
const indexes = resp.indexes.map(index => {
return new VectorIndexInfo(index.index_name);
});
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
resolve(new ListVectorIndexes.Success(indexes));
}
}
Expand Down
10 changes: 6 additions & 4 deletions packages/client-sdk-web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/client-sdk-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"xhr2": "0.2.1"
},
"dependencies": {
"@gomomento/generated-types-webtext": "0.94.1",
"@gomomento/generated-types-webtext": "0.96.0",
"@gomomento/sdk-core": "file:../core",
"google-protobuf": "3.21.2",
"grpc-web": "1.4.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
_CreateIndexRequest,
_ListIndexesRequest,
_DeleteIndexRequest,
_SimilarityMetric,
} from '@gomomento/generated-types-webtext/dist/controlclient_pb';
import {cacheServiceErrorMapper} from '../errors/cache-service-error-mapper';
import {
Expand Down Expand Up @@ -84,18 +85,21 @@ export class VectorIndexControlClient<

similarityMetric ??= VectorSimilarityMetric.COSINE_SIMILARITY;

const similarityMetricPb = new _SimilarityMetric();
switch (similarityMetric) {
case VectorSimilarityMetric.INNER_PRODUCT:
request.setInnerProduct(new _CreateIndexRequest._InnerProduct());
similarityMetricPb.setInnerProduct(
new _SimilarityMetric._InnerProduct()
);
break;
case VectorSimilarityMetric.EUCLIDEAN_SIMILARITY:
request.setEuclideanSimilarity(
new _CreateIndexRequest._EuclideanSimilarity()
similarityMetricPb.setEuclideanSimilarity(
new _SimilarityMetric._EuclideanSimilarity()
);
break;
case VectorSimilarityMetric.COSINE_SIMILARITY:
request.setCosineSimilarity(
new _CreateIndexRequest._CosineSimilarity()
similarityMetricPb.setCosineSimilarity(
new _SimilarityMetric._CosineSimilarity()
);
break;
default:
Expand All @@ -106,6 +110,7 @@ export class VectorIndexControlClient<
)
);
}
request.setSimilarityMetric(similarityMetricPb);

this.logger.debug("Issuing 'createIndex' request");
return await new Promise<CreateVectorIndex.Response>(resolve => {
Expand Down Expand Up @@ -141,9 +146,9 @@ export class VectorIndexControlClient<
resolve(new ListVectorIndexes.Error(cacheServiceErrorMapper(err)));
} else {
const indexes: VectorIndexInfo[] = resp
.getIndexNamesList()
.map((name: string) => {
return new VectorIndexInfo(name);
.getIndexesList()
.map(index => {
return new VectorIndexInfo(index.getIndexName());
});
resolve(new ListVectorIndexes.Success(indexes));
}
Expand Down

0 comments on commit 0bd5d6d

Please sign in to comment.