Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mandatory vector field causes type errors #24

Open
as-celegen opened this issue May 5, 2024 · 2 comments
Open

Mandatory vector field causes type errors #24

as-celegen opened this issue May 5, 2024 · 2 comments

Comments

@as-celegen
Copy link

as-celegen commented May 5, 2024

Upsert Command

vector-js/README.md

Lines 76 to 84 in 801c666

//Update Data
await index.upsert({
id: "upstash-rocks",
metadata: {
title: 'Star Wars',
genre: 'sci-fi',
category: 'classic'
}
});

Here it is shown upsert command can be called without the vector or data fields to update the metadata information in the index but this is not compatible with the defined type for argument of the upsert command in:
type VectorPayload<TMetadata> = {
id: number | string;
vector: number[];
metadata?: NoInfer<TMetadata>;
};
type DataPayload<TMetadata> = {
id: number | string;
data: string;
metadata?: NoInfer<TMetadata>;
};
type PayloadArray<TMetadata> = VectorPayload<TMetadata>[] | DataPayload<TMetadata>[];

constructor(
payload: VectorPayload<TMetadata> | DataPayload<TMetadata> | PayloadArray<TMetadata>
) {

Fetch, Range, Query

Commands fetch, query and range has a field called "includeVector" in their argument to specify whether vector field will be included in their return value. However their returned type specify vector field as always returned.

export type Vector<TMetadata = Record<string, unknown>> = {
id: string;
vector: number[];
metadata?: TMetadata;
};

type FetchCommandOptions = {
includeMetadata?: boolean;
includeVectors?: boolean;
};

export type FetchResult<TMetadata = Record<string, unknown>> = Vector<TMetadata> | null;

type RangeCommandPayload = {
cursor: number | string;
limit: number;
includeVectors?: boolean;
includeMetadata?: boolean;
};

export type RangeResult<TMetadata = Record<string, unknown>> = {
nextCursor: string;
vectors: Vector<TMetadata>[];
};

type QueryCommandPayload = {
topK: number;
filter?: string;
includeVectors?: boolean;
includeMetadata?: boolean;
} & ({ vector: number[]; data?: never } | { data: string; vector?: never });

export type QueryResult<TMetadata = Record<string, unknown>> = {
id: number | string;
score: number;
vector: number[];
metadata?: TMetadata;
};

@fahreddinozcan
Copy link
Collaborator

Hey,

thanks for the heads up here. We'll prioritize this and solve it as soon as possible.

@fahreddinozcan
Copy link
Collaborator

Hey, we've fixed the problem with the upsert method. However, there's a problem with the includeVector issue which is caused by TypeScript. We'll work on it and keep you updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants