Skip to content

Commit

Permalink
refactor: rename mvi parameter ids to filter in get/delete (#1141)
Browse files Browse the repository at this point in the history
To standardize how we select items in get item batch, get item metadata batch, and delete item batch, we use the term filter in methods, whether selecting by ids or filter expression.
  • Loading branch information
malandis authored Feb 12, 2024
1 parent 39f6753 commit 6576f21
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 46 deletions.
24 changes: 12 additions & 12 deletions packages/client-sdk-nodejs/src/internal/vector-index-data-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export class VectorIndexDataClient implements IVectorIndexDataClient {

public async deleteItemBatch(
indexName: string,
ids: Array<string>
filter: Array<string>
): Promise<VectorDeleteItemBatch.Response> {
try {
validateIndexName(indexName);
Expand All @@ -236,16 +236,16 @@ export class VectorIndexDataClient implements IVectorIndexDataClient {
err => new VectorDeleteItemBatch.Error(err)
);
}
return await this.sendDeleteItemBatch(indexName, ids);
return await this.sendDeleteItemBatch(indexName, filter);
}

private async sendDeleteItemBatch(
indexName: string,
ids: Array<string>
filter: Array<string>
): Promise<VectorDeleteItemBatch.Response> {
const request = new vectorindex._DeleteItemBatchRequest({
index_name: indexName,
filter: VectorIndexDataClient.idsToFilterExpression(ids),
filter: VectorIndexDataClient.idsToFilterExpression(filter),
});
return await new Promise((resolve, reject) => {
this.client.DeleteItemBatch(
Expand Down Expand Up @@ -697,7 +697,7 @@ export class VectorIndexDataClient implements IVectorIndexDataClient {

public async getItemBatch(
indexName: string,
ids: string[]
filter: string[]
): Promise<VectorGetItemBatch.Response> {
try {
validateIndexName(indexName);
Expand All @@ -707,16 +707,16 @@ export class VectorIndexDataClient implements IVectorIndexDataClient {
err => new VectorGetItemBatch.Error(err)
);
}
return await this.sendGetItemBatch(indexName, ids);
return await this.sendGetItemBatch(indexName, filter);
}

private async sendGetItemBatch(
indexName: string,
ids: string[]
filter: string[]
): Promise<VectorGetItemBatch.Response> {
const request = new vectorindex._GetItemBatchRequest({
index_name: indexName,
filter: VectorIndexDataClient.idsToFilterExpression(ids),
filter: VectorIndexDataClient.idsToFilterExpression(filter),
metadata_fields: VectorIndexDataClient.buildMetadataRequest({
metadataFields: ALL_VECTOR_METADATA,
}),
Expand Down Expand Up @@ -764,7 +764,7 @@ export class VectorIndexDataClient implements IVectorIndexDataClient {

public async getItemMetadataBatch(
indexName: string,
ids: string[]
filter: string[]
): Promise<VectorGetItemMetadataBatch.Response> {
try {
validateIndexName(indexName);
Expand All @@ -774,16 +774,16 @@ export class VectorIndexDataClient implements IVectorIndexDataClient {
err => new VectorGetItemMetadataBatch.Error(err)
);
}
return await this.sendGetItemMetadataBatch(indexName, ids);
return await this.sendGetItemMetadataBatch(indexName, filter);
}

private async sendGetItemMetadataBatch(
indexName: string,
ids: string[]
filter: string[]
): Promise<VectorGetItemMetadataBatch.Response> {
const request = new vectorindex._GetItemMetadataBatchRequest({
index_name: indexName,
filter: VectorIndexDataClient.idsToFilterExpression(ids),
filter: VectorIndexDataClient.idsToFilterExpression(filter),
metadata_fields: VectorIndexDataClient.buildMetadataRequest({
metadataFields: ALL_VECTOR_METADATA,
}),
Expand Down
24 changes: 12 additions & 12 deletions packages/client-sdk-web/src/internal/vector-index-data-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export class VectorIndexDataClient implements IVectorIndexDataClient {

public async deleteItemBatch(
indexName: string,
ids: Array<string>
filter: Array<string>
): Promise<VectorDeleteItemBatch.Response> {
try {
validateIndexName(indexName);
Expand All @@ -221,16 +221,16 @@ export class VectorIndexDataClient implements IVectorIndexDataClient {
err => new VectorDeleteItemBatch.Error(err)
);
}
return await this.sendDeleteItemBatch(indexName, ids);
return await this.sendDeleteItemBatch(indexName, filter);
}

private async sendDeleteItemBatch(
indexName: string,
ids: Array<string>
filter: Array<string>
): Promise<VectorDeleteItemBatch.Response> {
const request = new vectorindex._DeleteItemBatchRequest();
request.setIndexName(indexName);
request.setFilter(VectorIndexDataClient.idsToFilterExpression(ids));
request.setFilter(VectorIndexDataClient.idsToFilterExpression(filter));

return await new Promise((resolve, reject) => {
this.client.deleteItemBatch(
Expand Down Expand Up @@ -689,7 +689,7 @@ export class VectorIndexDataClient implements IVectorIndexDataClient {

public async getItemBatch(
indexName: string,
ids: string[]
filter: string[]
): Promise<VectorGetItemBatch.Response> {
try {
validateIndexName(indexName);
Expand All @@ -699,16 +699,16 @@ export class VectorIndexDataClient implements IVectorIndexDataClient {
err => new VectorGetItemBatch.Error(err)
);
}
return await this.sendGetItemBatch(indexName, ids);
return await this.sendGetItemBatch(indexName, filter);
}

private async sendGetItemBatch(
indexName: string,
ids: string[]
filter: string[]
): Promise<VectorGetItemBatch.Response> {
const request = new vectorindex._GetItemBatchRequest();
request.setIndexName(indexName);
request.setFilter(VectorIndexDataClient.idsToFilterExpression(ids));
request.setFilter(VectorIndexDataClient.idsToFilterExpression(filter));
request.setMetadataFields(
VectorIndexDataClient.buildMetadataRequest({
metadataFields: ALL_VECTOR_METADATA,
Expand Down Expand Up @@ -761,7 +761,7 @@ export class VectorIndexDataClient implements IVectorIndexDataClient {

public async getItemMetadataBatch(
indexName: string,
ids: string[]
filter: string[]
): Promise<VectorGetItemMetadataBatch.Response> {
try {
validateIndexName(indexName);
Expand All @@ -771,16 +771,16 @@ export class VectorIndexDataClient implements IVectorIndexDataClient {
err => new VectorGetItemMetadataBatch.Error(err)
);
}
return await this.sendGetItemMetadataBatch(indexName, ids);
return await this.sendGetItemMetadataBatch(indexName, filter);
}

private async sendGetItemMetadataBatch(
indexName: string,
ids: string[]
filter: string[]
): Promise<VectorGetItemMetadataBatch.Response> {
const request = new vectorindex._GetItemMetadataBatchRequest();
request.setIndexName(indexName);
request.setFilter(VectorIndexDataClient.idsToFilterExpression(ids));
request.setFilter(VectorIndexDataClient.idsToFilterExpression(filter));
request.setMetadataFields(
VectorIndexDataClient.buildMetadataRequest({
metadataFields: ALL_VECTOR_METADATA,
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/clients/IVectorIndexClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ export interface IVectorIndexClient extends IVectorIndexControlClient {

deleteItemBatch(
indexName: string,
ids: Array<string>
filter: Array<string>
): Promise<VectorDeleteItemBatch.Response>;

getItemBatch(
indexName: string,
ids: Array<string>
filter: Array<string>
): Promise<VectorGetItemBatch.Response>;

getItemMetadataBatch(
indexName: string,
ids: Array<string>,
filter: Array<string>,
metadataFields?: Array<string>
): Promise<VectorGetItemMetadataBatch.Response>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import {
DeleteVectorIndex,
ListVectorIndexes,
VectorCountItems,
VectorUpsertItemBatch,
VectorSearch,
VectorSearchAndFetchVectors,
VectorDeleteItemBatch,
VectorGetItemBatch,
VectorGetItemMetadataBatch,
VectorSearch,
VectorSearchAndFetchVectors,
VectorUpsertItemBatch,
} from '../../..';
import {
IVectorIndexClient,
Expand Down Expand Up @@ -83,7 +83,7 @@ export abstract class AbstractVectorIndexClient
}

/**
* Deletes a vector index and all the vectors stored in it.
* Deletes a vector index and all the items stored in it.
*
* @param {string} indexName - The name of the vector index to delete.
* @returns {Promise<DeleteVectorIndex.Response>} -
Expand Down Expand Up @@ -188,47 +188,47 @@ export abstract class AbstractVectorIndexClient
* Deletes any and all items with the given IDs from the index.
*
* @param {string} indexName - Name of the index to delete the items from.
* @param {Array<string>} ids - The IDs of the items to be deleted from the index.
* @param {Array<string>} filter - The IDs of the items to be deleted from the index.
* @returns {Promise<VectorDeleteItemBatch.Response>}
* {@link VectorDeleteItemBatch.Success} on success.
* {@link VectorDeleteItemBatch.Error} on error.
*/
public async deleteItemBatch(
indexName: string,
ids: Array<string>
filter: Array<string>
): Promise<VectorDeleteItemBatch.Response> {
return await this.dataClient.deleteItemBatch(indexName, ids);
return await this.dataClient.deleteItemBatch(indexName, filter);
}

/**
* Gets a batch of items from a vector index by ID.
*
* @param indexName - Name of the index to get the items from.
* @param ids - The IDs of the items to be retrieved from the index.
* @param filter - The IDs of the items to be retrieved from the index.
* @returns {Promise<VectorGetItemBatch.Response>}
* {@link VectorGetItemBatch.Success} on success, with the found items.
* {@link VectorGetItemBatch.Error} on error.
*/
public async getItemBatch(
indexName: string,
ids: string[]
filter: string[]
): Promise<VectorGetItemBatch.Response> {
return await this.dataClient.getItemBatch(indexName, ids);
return await this.dataClient.getItemBatch(indexName, filter);
}

/**
* Gets metadata for a batch of items from a vector index by ID.
*
* @param indexName - Name of the index to get the items from.
* @param ids - The IDs of the items to be retrieved from the index.
* @param filter - The IDs of the items to be retrieved from the index.
* @returns {Promise<VectorGetItemMetadataBatch.Response>}
* {@link VectorGetItemMetadataBatch.Success} on success, with the found item metadata.
* {@link VectorGetItemMetadataBatch.Error} on error.
*/
public async getItemMetadataBatch(
indexName: string,
ids: string[]
filter: string[]
): Promise<VectorGetItemMetadataBatch.Response> {
return await this.dataClient.getItemMetadataBatch(indexName, ids);
return await this.dataClient.getItemMetadataBatch(indexName, filter);
}
}
Original file line number Diff line number Diff line change
@@ -1,41 +1,47 @@
import {
VectorCountItems,
VectorUpsertItemBatch,
VectorDeleteItemBatch,
VectorSearch,
VectorSearchAndFetchVectors,
VectorGetItemBatch,
VectorGetItemMetadataBatch,
VectorSearch,
VectorSearchAndFetchVectors,
VectorUpsertItemBatch,
} from '../../../messages/responses/vector';
import {VectorIndexItem} from '../../../messages/vector-index';
import {SearchOptions} from '../../../clients/IVectorIndexClient';

export interface IVectorIndexDataClient {
countItems(indexName: string): Promise<VectorCountItems.Response>;

upsertItemBatch(
indexName: string,
items: Array<VectorIndexItem>
): Promise<VectorUpsertItemBatch.Response>;

search(
indexName: string,
queryVector: Array<number>,
options?: SearchOptions
): Promise<VectorSearch.Response>;

searchAndFetchVectors(
indexName: string,
queryVector: Array<number>,
options?: SearchOptions
): Promise<VectorSearchAndFetchVectors.Response>;

deleteItemBatch(
indexName: string,
ids: Array<string>
filter: Array<string>
): Promise<VectorDeleteItemBatch.Response>;

getItemBatch(
indexName: string,
ids: Array<string>
filter: Array<string>
): Promise<VectorGetItemBatch.Response>;

getItemMetadataBatch(
indexName: string,
ids: Array<string>
filter: Array<string>
): Promise<VectorGetItemMetadataBatch.Response>;
}

0 comments on commit 6576f21

Please sign in to comment.