Open as-celegen opened 2 weeks ago
Hello there, this is not an error maybe a misunderstading. Suppose you have something like this:
const res = await index.queryMany<{
animal: string;
tags: string[];
diet: string;
}>([
{
vector: initialData[0].vector,
topK: 2,
filter: "tags[0] = 'mammal' AND diet = 'herbivore'",
includeMetadata: true,
},
{
vector: initialData[1].vector,
topK: 1,
filter: "tags[0] = 'mammal' AND diet = 'carnivore'",
includeMetadata: true,
},
]);
When you say topK=2 and topK=1, you will get this:
[
[
{
id: `id1`,
score: 1,
metadata: { animal: "elephant", tags: ["mammal"], diet: "herbivore" },
},
{
id: `id2`,
score: 1,
metadata: { animal: "elephant", tags: ["mammal"], diet: "herbivore" },
},
],
[
{
id: `id2-1`,
score: 1,
metadata: { animal: "tiger", tags: ["mammal"], diet: "carnivore" },
},
],
]
Your inner array has to match topK thats why we return list of lists.
Sorry about initial phrasing, i meant if a list of queries with only one query is given to queryMany, response is same as if i send that query with query function. Example:
const res = await index.queryMany<
{ animal: string; tags: string[]; diet: string; }
>([
{
vector: initialData[0].vector,
topK: 2,
filter: "tags[0] = 'mammal' AND diet = 'herbivore'"
, includeMetadata: true,
}, ]);
Response:
[ { id:
id1, score: 1, metadata: { animal: "elephant", tags: ["mammal"], diet: "herbivore" }, }, { id:
id2, score: 1, metadata: { animal: "elephant", tags: ["mammal"], diet: "herbivore" }, }, ]
In this case, what you want to do is use query
instead of queryMany
. To prevent this misunderstanding, I think we should improve the types a little bit. I agree.
If single query list is given to queryMany like
index.queryMany([{vector: [1, 0, 0], topK: 6}])
, return value is one dimensional list just as normal query function. Return type of queryMany is defined as two dimensional list.