Skip to content
New issue

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

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

Already on GitHub? # to your account

Single Server | GpuIndexFlatL2 Write Strategy #1072

Closed
2 tasks
dexception opened this issue Dec 30, 2019 · 4 comments
Closed
2 tasks

Single Server | GpuIndexFlatL2 Write Strategy #1072

dexception opened this issue Dec 30, 2019 · 4 comments
Labels

Comments

@dexception
Copy link

Running on:

  • CPU
  • [yes] GPU

Interface:

  • [ yes] C++
  • Python

About my app:

  1. Multi threaded http server based application
  2. Accepts id and vector for /add request
  3. Provide GpuIndexFlatL2 search functionality

However all the adding and search is happending in memory and if the application closes or crashes the data is lost. My question is since faiss supports writing index via:

    const char *name = "index.bin";
    faiss::write_index(faiss::gpu::index_gpu_to_cpu(index), name);

how do i implement the most efficient index saving strategy ?

  1. Block all requests while index is being written to file for every new vector added
    This will lead to decrease in performance.

  2. Periodically update the index in the background after every 10,000 new vectors
    if application crashes unwritten new vectors will be lost

  3. Other strategy ?

Please help me. I have been scratching my head for the last 2 weeks regarding this problem.

@mdouze
Copy link
Contributor

mdouze commented Dec 31, 2019

It really depends on the operating conditions.
One approach is with two indexes: one big one with most of the vectors, and one in which you add new vectors. At search time, you search in both.

Then you can save every 10k adds with:

  1. save small index with (fast) with incremental file names

  2. merge small index into big one (fast, in RAM)

  3. clear small index.

At recover time, you then need to load the small indexes to reconstruct the big one. You could have a background job that merges the small indexes on disk.

@dexception
Copy link
Author

dexception commented Dec 31, 2019

Thanks i think this would work without data loss in case of failure.

Other question is how do you handle meta data for the vectors because when the results for distance search are achieved that might not be revelant. For example,

In our application we have clientId,categoryId for each vector and other attributes as well. So when the topK results are returned that might not be for that clientID. Is there an Index that suports adding attributes for vectors inside the index as well ?

@mdouze
Copy link
Contributor

mdouze commented Jan 2, 2020

No, you need to put metadata in a separate conventional table.
Rationale in #641

@dexception
Copy link
Author

Resolved.

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

No branches or pull requests

2 participants