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

QueryMany type error #38

Open
as-celegen opened this issue Jun 29, 2024 · 3 comments
Open

QueryMany type error #38

as-celegen opened this issue Jun 29, 2024 · 3 comments

Comments

@as-celegen
Copy link

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.

@ogzhanolguncu
Copy link
Contributor

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.

@as-celegen
Copy link
Author

as-celegen commented Jul 5, 2024

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" }, }, ]

@ogzhanolguncu
Copy link
Contributor

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.

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