Repository: qdrant/qdrant (language: rust)

Issue:
GPU indexing does not work with payload
I try to use GPU indexing on small index with payload

## Current Behavior
Qdrant panicked after starting indexation of payload field indexes

## Steps to Reproduce
1. create new collection with default qdrant config + gpu.indexing = true
2. create payload indexes
3. upload data thought qdrant-client(rust). 2000000 vectors D=512

config with  optimizer status

```json
{
  "result": {
    "status": "red",
    "optimizer_status": {
      "error": "Service internal error: Optimization task panicked: removal index (is 0) should be < len (is 0)"
    },
    "indexed_vectors_count": 0,
    "points_count": 207041,
    "segments_count": 8,
    "config": {
      "params": {
        "vectors": {
          "size": 512,
          "distance": "Cosine",
          "on_disk": true
        },
        "shard_number": 1,
        "replication_factor": 1,
        "write_consistency_factor": 1,
        "on_disk_payload": true
      },
      "hnsw_config": {
        "m": 32,
        "ef_construct": 128,
        "full_scan_threshold": 10000,
        "max_indexing_threads": 0,
        "on_disk": true
      },
      "optimizer_config": {
        "deleted_threshold": 0.2,
        "vacuum_min_vector_number": 1000,
        "default_segment_number": 0,
        "max_segment_size": null,
        "memmap_threshold": 10000,
        "indexing_threshold": 20000,
        "flush_interval_sec": 5,
        "max_optimization_threads": null
      },
      "wal_config": {
        "wal_capacity_mb": 32,
        "wal_segments_ahead": 0
      },
      "quantization_config": {
        "scalar": {
          "type": "int8",
          "quantile": 0.99,
          "always_ram": true
        }
      },
      "strict_mode_config": {
        "enabled": false
      }
    },
    "payload_schema": {
      "c1": {
        "data_type": "integer",
        "params": {
          "type": "integer",
          "lookup": true,
          "range": true,
          "is_principal": null,
          "on_disk": false
        },
        "points": 12252
      },
      "p1": {
        "data_type": "datetime",
        "params": {
          "type": "datetime",
          "is_principal": null,
          "on_disk": false
        },
        "points": 79797
      },
      "t1": {
        "data_type": "keyword",
        "params": {
          "type": "keyword",
          "on_disk": false
        },
        "points": 79797
      },
      "f1": {
        "data_type": "integer",
        "params": {
          "type": "integer",
          "lookup": true,
          "range": true,
          "is_principal": null,
          "on_disk": false
        },
        "points": 38570
      },
      "a1": {
        "data_type": "keyword",
        "params": {
          "type": "keyword",
          "on_disk": false
        },
        "points": 79797
      },
      "p2": {
        "data_type": "keyword",
        "params": {
          "type": "keyword",
          "on_disk": false
        },
        "points": 79797
      },
      "l1": {
        "data_type": "integer",
        "params": {
          "type": "integer",
          "lookup": true,
          "range": true,
          "is_principal": null,
          "on_disk": false
        },
        "points": 0
      }
    }
  },
  "status": "ok",
  "time": 0.00009899
}
```

log of qdrant. i built from source

```log
2025-01-17T12:46:17.247549Z DEBUG segment::index::hnsw_index::hnsw: building HNSW for 19927 vectors with 1 CPUs and GPU    
2025-01-17T12:46:17.284228Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 7.949189ms    
2025-01-17T12:46:17.325421Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 41.158017ms    
2025-01-17T12:46:17.555323Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 4    
2025-01-17T12:46:17.559169Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 3    
2025-01-17T12:46:17.562265Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 2    
2025-01-17T12:46:17.567253Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 1    
2025-01-17T12:46:17.598774Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 0    
2025-01-17T12:46:17.601496Z DEBUG collection::update_handler: Optimizing segments: [0, 7]    
2025-01-17T12:46:17.724459Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph patches time: 138.817831ms, count 48, avg 2.892038ms    
2025-01-17T12:46:17.724470Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph update entries time: 21.479809ms, count 152, avg 141.314µs    
2025-01-17T12:46:17.725137Z DEBUG segment::index::hnsw_index::hnsw: Finish main graph in time 476.098102ms    
2025-01-17T12:46:17.725383Z DEBUG segment::index::hnsw_index::hnsw: building additional index for field f1   
2025-01-17T12:46:17.725404Z DEBUG segment::index::hnsw_index::hnsw: building additional index for field a1    
2025-01-17T12:46:17.725474Z DEBUG segment::index::hnsw_index::hnsw: building additional index for field c1    
2025-01-17T12:46:17.734271Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 7.796939ms    
2025-01-17T12:46:17.775174Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 40.871079ms    
2025-01-17T12:46:17.981914Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 0    
2025-01-17T12:46:17.998076Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph patches time: 9.925018ms, count 7, avg 1.417859ms    
2025-01-17T12:46:17.998090Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph update entries time: 0ns, count 0, avg 0ns    
2025-01-17T12:46:18.000249Z DEBUG segment::index::hnsw_index::hnsw: building additional index for field l1    
2025-01-17T12:46:18.000479Z ERROR qdrant::startup: Panic backtrace: 
   0: qdrant::startup::setup_panic_hook::{{closure}}
   1: std::panicking::rust_panic_with_hook
   2: std::panicking::begin_panic_handler::{{closure}}
   3: std::sys::backtrace::__rust_end_short_backtrace
   4: rust_begin_unwind
   5: core::panicking::panic_fmt
   6: alloc::vec::Vec<T,A>::remove::assert_failed
   7: segment::index::hnsw_index::hnsw::HNSWIndex::build_index
   8: segment::index::hnsw_index::hnsw::HNSWIndex::open
   9: segment::segment_constructor::segment_constructor_base::create_vector_index
  10: segment::segment_constructor::segment_builder::SegmentBuilder::build
  11: collection::collection_manager::optimizers::segment_optimizer::SegmentOptimizer::build_new_segment
  12: collection::collection_manager::optimizers::segment_optimizer::SegmentOptimizer::optimize
  13: tokio::runtime::task::raw::poll
  14: std::sys::backtrace::__rust_begin_short_backtrace
  15: core::ops::function::FnOnce::call_once{{vtable.shim}}
  16: std::sys::pal::unix::thread::Thread::new::thread_start
  17: start_thread
             at ./nptl/pthread_create.c:447:8
  18: clone3
             at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
    
2025-01-17T12:46:18.000492Z ERROR qdrant::startup: Panic occurred in file lib/segment/src/index/hnsw_index/gpu/batched_points.rs at line 48: removal index (is 0) should be < len (is 0)    
2025-01-17T12:46:18.603939Z  WARN collection::update_handler: Optimization task panicked, collection may be in unstable state: removal index (is 0) should be < len (is 0)
```

qdrant version: 1.13.0
OS: Ubuntu 24.04
GPU: NVIDIA



Discussion / hints:
Thanks for the early run, I was surprised about it, we have not even published running instructions. Working on this problem, I caught something related but on low-end integrated amd gpu
Can you retry your test to check that this bug is stable and reproducible? Can you also check if you have such problems on this dataset without payload indices? These checks may help me to fix this problem faster
I use method upsert_points with 128 vectors 
> Can you retry your test to check that this bug is stable and reproducible? Can you also check if you have such problems on this dataset without payload indices? These checks may help me to fix this problem faster

Yes I can.
> Thanks for the early run, I was surprised about it, we have not even published running instructions. Working on this problem, I caught something related but on low-end integrated amd gpu

I have integrated gpu AMD too

I did not set `device_filter`
> > Thanks for the early run, I was surprised about it, we have not even published running instructions. Working on this problem, I caught something related but on low-end integrated amd gpu
> 
> I has integrated gpu AMD too
> 
> I did not set `device_filter`

By default, we don't use integrated GPU. Details will appear later in the documentation. There is an additional setting to allow integrated GPUs, you don't need to filter your Nvidia device. If you wish, you can enable it using the `QDRANT__GPU__allow_integarted` config parameter. (!!!) You won't have additional performance, for your setup it doesn't make any sense and you will get even worse performance because you will wait for the latest HNSW from the integrated chip while nvidia is idle
You can see in first logs after start which devices were found and which devices were initialized to use
> You can see in first logs after start which devices were found and which devices were initialized to use

I saw.
found: nvidia and amd gpu
initialized: nvidia
> Can you retry your test to check that this bug is stable and reproducible? Can you also check if you have such problems on this dataset without payload indices? These checks may help me to fix this problem faster

I tried again with the same setup

```sh
curl http://localhost:6333/collections
{"result":{"collections":[]},"status":"ok","time":6.7e-6}
```

```log
2025-01-17T13:37:39.082600Z  INFO storage::content_manager::toc::collection_meta_ops: Creating collection test-gpu    
2025-01-17T13:37:39.350226Z DEBUG collection::collection: Changing shard test-gpu:0 replica state from Some(Initializing) to Active    
2025-01-17T13:37:39.350244Z DEBUG collection::shards::replica_set: Changing local shard test-gpu:0 state from Some(Initializing) to Active    
2025-01-17T13:37:39.359522Z DEBUG storage::content_manager::toc::collection_meta_ops: Create payload index CreatePayloadIndex { collection_name: "test-gpu", field_name: JsonPath { first_key: "p2", rest: [] }, field_schema: FieldParams(Keyword(KeywordIndexParams { type: Keyword, is_tenant: None, on_disk: Some(false) })) }    
2025-01-17T13:37:39.368414Z DEBUG storage::content_manager::toc::collection_meta_ops: Create payload index CreatePayloadIndex { collection_name: "test-gpu", field_name: JsonPath { first_key: "a1", rest: [] }, field_schema: FieldParams(Keyword(KeywordIndexParams { type: Keyword, is_tenant: None, on_disk: Some(false) })) }    
2025-01-17T13:37:39.383055Z DEBUG storage::content_manager::toc::collection_meta_ops: Create payload index CreatePayloadIndex { collection_name: "test-gpu", field_name: JsonPath { first_key: "t1", rest: [] }, field_schema: FieldParams(Keyword(KeywordIndexParams { type: Keyword, is_tenant: None, on_disk: Some(false) })) }    
2025-01-17T13:37:39.397076Z DEBUG storage::content_manager::toc::collection_meta_ops: Create payload index CreatePayloadIndex { collection_name: "test-gpu", field_name: JsonPath { first_key: "l1", rest: [] }, field_schema: FieldParams(Integer(IntegerIndexParams { type: Integer, lookup: Some(true), range: Some(true), is_principal: None, on_disk: Some(false) })) }    
2025-01-17T13:37:39.411723Z DEBUG storage::content_manager::toc::collection_meta_ops: Create payload index CreatePayloadIndex { collection_name: "test-gpu", field_name: JsonPath { first_key: "c1", rest: [] }, field_schema: FieldParams(Integer(IntegerIndexParams { type: Integer, lookup: Some(true), range: Some(true), is_principal: None, on_disk: Some(false) })) }    
2025-01-17T13:37:39.428742Z DEBUG storage::content_manager::toc::collection_meta_ops: Create payload index CreatePayloadIndex { collection_name: "test-gpu", field_name: JsonPath { first_key: "f1", rest: [] }, field_schema: FieldParams(Integer(IntegerIndexParams { type: Integer, lookup: Some(true), range: Some(true), is_principal: None, on_disk: Some(false) })) }    
2025-01-17T13:37:39.443034Z DEBUG storage::content_manager::toc::collection_meta_ops: Create payload index CreatePayloadIndex { collection_name: "test-gpu", field_name: JsonPath { first_key: "p1", rest: [] }, field_schema: FieldParams(Datetime(DatetimeIndexParams { type: Datetime, is_principal: None, on_disk: Some(false) })) } 
```

dashboard console output

```json
{
  "result": {
    "collections": [
      {
        "name": "test-gpu"
      }
    ]
  },
  "status": "ok",
  "time": 0.00000512
}
```

part of output dashboard console

```json
"status": "red",
    "optimizer_status": {
      "error": "Service internal error: Optimization task panicked: removal index (is 0) should be < len (is 0)"
    },
    "indexed_vectors_count": 0,
    "points_count": 149793,
```

```log
2025-01-17T13:58:08.042665Z DEBUG collection::update_handler: Optimizing segments: [7, 3]    
2025-01-17T13:58:09.709039Z DEBUG segment::index::hnsw_index::hnsw: building HNSW for 19874 vectors with 1 CPUs and GPU NVIDIA GeForce RTX  
2025-01-17T13:58:09.835728Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 46.19407ms    
2025-01-17T13:58:09.878261Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 42.488616ms    
2025-01-17T13:58:10.047773Z DEBUG collection::update_handler: Optimizing segments: [4, 5]    
2025-01-17T13:58:10.118159Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 3    
2025-01-17T13:58:10.138547Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 2    
2025-01-17T13:58:10.144451Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 1    
2025-01-17T13:58:10.200204Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 0    
2025-01-17T13:58:10.364648Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph patches time: 182.58317ms, count 47, avg 3.884748ms    
2025-01-17T13:58:10.364661Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph update entries time: 39.322867ms, count 113, avg 347.989µs    
2025-01-17T13:58:10.365272Z DEBUG segment::index::hnsw_index::hnsw: Finish main graph in time 654.064351ms    
2025-01-17T13:58:10.365438Z DEBUG segment::index::hnsw_index::hnsw: building additional index for field p2    
2025-01-17T13:58:10.365446Z DEBUG segment::index::hnsw_index::hnsw: building additional index for field c1   
2025-01-17T13:58:10.373971Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 7.724489ms    
2025-01-17T13:58:10.414412Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 40.406883ms    
2025-01-17T13:58:10.419857Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 0    
2025-01-17T13:58:10.431860Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph patches time: 6.614943ms, count 6, avg 1.10249ms    
2025-01-17T13:58:10.431870Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph update entries time: 0ns, count 0, avg 0ns    
2025-01-17T13:58:10.433951Z DEBUG segment::index::hnsw_index::hnsw: building additional index for field f1    
2025-01-17T13:58:10.433978Z DEBUG segment::index::hnsw_index::hnsw: building additional index for field t1    
2025-01-17T13:58:10.433983Z DEBUG segment::index::hnsw_index::hnsw: building additional index for field l1
2025-01-17T13:58:10.468038Z ERROR qdrant::startup: Panic backtrace: 
   0: qdrant::startup::setup_panic_hook::{{closure}}
   1: std::panicking::rust_panic_with_hook
   2: std::panicking::begin_panic_handler::{{closure}}
   3: std::sys::backtrace::__rust_end_short_backtrace
   4: rust_begin_unwind
   5: core::panicking::panic_fmt
   6: alloc::vec::Vec<T,A>::remove::assert_failed
   7: segment::index::hnsw_index::hnsw::HNSWIndex::build_index
   8: segment::index::hnsw_index::hnsw::HNSWIndex::open
   9: segment::segment_constructor::segment_constructor_base::create_vector_index
  10: segment::segment_constructor::segment_builder::SegmentBuilder::build
  11: collection::collection_manager::optimizers::segment_optimizer::SegmentOptimizer::build_new_segment
  12: collection::collection_manager::optimizers::segment_optimizer::SegmentOptimizer::optimize
  13: tokio::runtime::task::raw::poll
  14: std::sys::backtrace::__rust_begin_short_backtrace
  15: core::ops::function::FnOnce::call_once{{vtable.shim}}
  16: std::sys::pal::unix::thread::Thread::new::thread_start
  17: start_thread
             at ./nptl/pthread_create.c:447:8
  18: clone3
             at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
    
2025-01-17T13:58:10.468056Z ERROR qdrant::startup: Panic occurred in file lib/segment/src/index/hnsw_index/gpu/batched_points.rs at line 48: removal index (is 0) should be < len (is 0)    
2025-01-17T13:58:11.044517Z  WARN collection::update_handler: Optimization task panicked, collection may be in unstable state: removal index (is 0) should be < len (is 0) 
```
> Can you retry your test to check that this bug is stable and reproducible? Can you also check if you have such problems on this dataset without payload indices? These checks may help me to fix this problem faster

It works without payload indexing.

```json
{
  "result": {
    "status": "yellow",
    "optimizer_status": "ok",
    "indexed_vectors_count": 217220,
    "points_count": 215643,
    "segments_count": 9,
    "config": {
      "params": {
        "vectors": {
          "size": 512,
          "distance": "Cosine",
          "on_disk": true
        },
        "shard_number": 1,
        "replication_factor": 1,
        "write_consistency_factor": 1,
        "on_disk_payload": true
      },
      "hnsw_config": {
        "m": 32,
        "ef_construct": 128,
        "full_scan_threshold": 10000,
        "max_indexing_threads": 0,
        "on_disk": true
      },
      "optimizer_config": {
        "deleted_threshold": 0.2,
        "vacuum_min_vector_number": 1000,
        "default_segment_number": 0,
        "max_segment_size": null,
        "memmap_threshold": 10000,
        "indexing_threshold": 20000,
        "flush_interval_sec": 5,
        "max_optimization_threads": null
      },
      "wal_config": {
        "wal_capacity_mb": 32,
        "wal_segments_ahead": 0
      },
      "quantization_config": {
        "scalar": {
          "type": "int8",
          "quantile": 0.99,
          "always_ram": true
        }
      },
      "strict_mode_config": {
        "enabled": false
      }
    },
    "payload_schema": {}
  },
  "status": "ok",
  "time": 0.000066949
}
```

```log
2025-01-17T14:12:56.538041Z DEBUG collection::update_handler: Optimizing segments: [7, 1]    
2025-01-17T14:12:57.222396Z DEBUG segment::index::hnsw_index::hnsw: building HNSW for 19786 vectors with 1 CPUs and GPU NVIDIA GeForce RTX    
2025-01-17T14:12:57.317878Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 49.952387ms    
2025-01-17T14:12:57.363561Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 45.639537ms    
2025-01-17T14:12:57.613577Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 3    
2025-01-17T14:12:57.627920Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 2    
2025-01-17T14:12:57.645179Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 1    
2025-01-17T14:12:57.740097Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 0    
2025-01-17T14:12:57.937325Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph patches time: 209.045877ms, count 47, avg 4.447784ms    
2025-01-17T14:12:57.937337Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph update entries time: 56.531198ms, count 113, avg 500.276µs    
2025-01-17T14:12:57.937982Z DEBUG segment::index::hnsw_index::hnsw: Finish main graph in time 713.915576ms    
2025-01-17T14:12:57.962062Z DEBUG segment::index::hnsw_index::hnsw: finish additional payload field indexing    
2025-01-17T14:13:19.539195Z DEBUG collection::update_handler: Optimizing segments: [6, 5]    
2025-01-17T14:13:20.229857Z DEBUG segment::index::hnsw_index::hnsw: building HNSW for 19930 vectors with 1 CPUs and GPU NVIDIA GeForce RTX    
2025-01-17T14:13:20.271208Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 8.448432ms    
2025-01-17T14:13:20.312664Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 41.415315ms    
2025-01-17T14:13:20.546861Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 3    
2025-01-17T14:13:20.561802Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 2    
2025-01-17T14:13:20.591468Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 1    
2025-01-17T14:13:20.662486Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 0    
2025-01-17T14:13:20.853674Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph patches time: 243.856952ms, count 47, avg 5.188445ms    
2025-01-17T14:13:20.853689Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph update entries time: 50.453935ms, count 113, avg 446.495µs    
2025-01-17T14:13:20.854335Z DEBUG segment::index::hnsw_index::hnsw: Finish main graph in time 622.808491ms    
2025-01-17T14:13:20.877494Z DEBUG segment::index::hnsw_index::hnsw: finish additional payload field indexing    
2025-01-17T14:13:42.539835Z DEBUG collection::update_handler: Optimizing segments: [15, 3]    
2025-01-17T14:13:43.280276Z DEBUG segment::index::hnsw_index::hnsw: building HNSW for 19876 vectors with 1 CPUs and GPU NVIDIA GeForce RTX    
2025-01-17T14:13:43.318329Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 8.516652ms    
2025-01-17T14:13:43.360168Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 41.800783ms    
2025-01-17T14:13:43.598814Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 3    
2025-01-17T14:13:43.645416Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 2    
2025-01-17T14:13:43.683652Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 1    
2025-01-17T14:13:43.817671Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 0    
2025-01-17T14:13:43.896055Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph patches time: 168.684975ms, count 47, avg 3.589042ms    
2025-01-17T14:13:43.896071Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph update entries time: 117.786365ms, count 113, avg 1.042357ms    
2025-01-17T14:13:43.896748Z DEBUG segment::index::hnsw_index::hnsw: Finish main graph in time 614.852415ms    
2025-01-17T14:13:43.920025Z DEBUG segment::index::hnsw_index::hnsw: finish additional payload field indexing    
2025-01-17T14:13:45.537716Z DEBUG collection::update_handler: Optimizing segments: [2, 19]    
2025-01-17T14:13:46.013047Z DEBUG segment::index::hnsw_index::hnsw: building HNSW for 11467 vectors with 1 CPUs and GPU NVIDIA GeForce RTX    
2025-01-17T14:13:46.047326Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 8.705301ms    
2025-01-17T14:13:46.090301Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 42.938048ms    
2025-01-17T14:13:46.326297Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 3    
2025-01-17T14:13:46.328142Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 2    
2025-01-17T14:13:46.330683Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 1    
2025-01-17T14:13:46.354251Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 0    
2025-01-17T14:13:46.447462Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph patches time: 105.034931ms, count 28, avg 3.751247ms    
2025-01-17T14:13:46.447476Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph update entries time: 11.332588ms, count 68, avg 166.655µs    
2025-01-17T14:13:46.447886Z DEBUG segment::index::hnsw_index::hnsw: Finish main graph in time 433.768504ms    
2025-01-17T14:13:46.465787Z DEBUG segment::index::hnsw_index::hnsw: finish additional payload field indexing    
2025-01-17T14:13:46.540898Z DEBUG collection::update_handler: Optimizing segments: [0]    
2025-01-17T14:13:46.612220Z DEBUG collection::update_handler: Optimizing segments: [0]    
2025-01-17T14:13:47.014826Z DEBUG segment::index::hnsw_index::hnsw: building HNSW for 10257 vectors with 1 CPUs and GPU NVIDIA GeForce RTX    
2025-01-17T14:13:47.060387Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 8.134893ms    
2025-01-17T14:13:47.101783Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 41.362865ms    
2025-01-17T14:13:47.338033Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 3    
2025-01-17T14:13:47.339709Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 2    
2025-01-17T14:13:47.344255Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 1    
2025-01-17T14:13:47.364317Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 0    
2025-01-17T14:13:47.444973Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph patches time: 89.651139ms, count 26, avg 3.44812ms    
2025-01-17T14:13:47.444987Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph update entries time: 12.753934ms, count 62, avg 205.708µs    
2025-01-17T14:13:47.445459Z DEBUG segment::index::hnsw_index::hnsw: Finish main graph in time 429.567461ms    
2025-01-17T14:13:47.462535Z DEBUG segment::index::hnsw_index::hnsw: finish additional payload field indexing    
2025-01-17T14:13:47.543480Z DEBUG collection::update_handler: Optimizing segments: [11]    
2025-01-17T14:13:47.543498Z DEBUG collection::update_handler: Optimizing segments: [4]    
2025-01-17T14:13:48.214994Z DEBUG segment::index::hnsw_index::hnsw: building HNSW for 10381 vectors with 1 CPUs and GPU NVIDIA GeForce RTX    
2025-01-17T14:13:48.250389Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 8.110834ms    
2025-01-17T14:13:48.292225Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 41.794604ms    
2025-01-17T14:13:48.523898Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 3    
2025-01-17T14:13:48.526608Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 2    
2025-01-17T14:13:48.528857Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 1    
2025-01-17T14:13:48.544642Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 0    
2025-01-17T14:13:48.616223Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph patches time: 78.502718ms, count 26, avg 3.019335ms    
2025-01-17T14:13:48.616236Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph update entries time: 9.087619ms, count 62, avg 146.574µs    
2025-01-17T14:13:48.616632Z DEBUG segment::index::hnsw_index::hnsw: Finish main graph in time 400.79407ms    
2025-01-17T14:13:48.631311Z DEBUG segment::index::hnsw_index::hnsw: finish additional payload field indexing    
2025-01-17T14:13:48.746870Z DEBUG segment::index::hnsw_index::hnsw: building HNSW for 10095 vectors with 1 CPUs and GPU NVIDIA GeForce RTX    
2025-01-17T14:13:48.801812Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 8.584362ms    
2025-01-17T14:13:48.844130Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 42.278121ms    
2025-01-17T14:13:49.074561Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 3    
2025-01-17T14:13:49.076332Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 2    
2025-01-17T14:13:49.078207Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 1    
2025-01-17T14:13:49.088538Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 0    
2025-01-17T14:13:49.137490Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph patches time: 51.672079ms, count 25, avg 2.066883ms    
2025-01-17T14:13:49.137497Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph update entries time: 6.973699ms, count 59, avg 118.198µs    
2025-01-17T14:13:49.137880Z DEBUG segment::index::hnsw_index::hnsw: Finish main graph in time 390.120768ms    
2025-01-17T14:13:49.152627Z DEBUG segment::index::hnsw_index::hnsw: finish additional payload field indexing    
2025-01-17T14:13:49.247335Z DEBUG collection::update_handler: Optimizing segments: [28, 30, 29]    
2025-01-17T14:13:49.703008Z DEBUG segment::index::hnsw_index::hnsw: building HNSW for 10607 vectors with 1 CPUs and GPU NVIDIA GeForce RTX    
2025-01-17T14:13:49.735860Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 8.559592ms    
2025-01-17T14:13:49.779432Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 43.526886ms    
2025-01-17T14:13:50.014110Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 3    
2025-01-17T14:13:50.015786Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 2    
2025-01-17T14:13:50.017862Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 1    
2025-01-17T14:13:50.028526Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 0    
2025-01-17T14:13:50.089501Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph patches time: 63.827944ms, count 26, avg 2.45492ms    
2025-01-17T14:13:50.089513Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph update entries time: 6.421311ms, count 62, avg 103.569µs    
2025-01-17T14:13:50.089917Z DEBUG segment::index::hnsw_index::hnsw: Finish main graph in time 386.228865ms    
2025-01-17T14:13:50.104588Z DEBUG segment::index::hnsw_index::hnsw: finish additional payload field indexing    
2025-01-17T14:14:11.543062Z DEBUG collection::update_handler: Optimizing segments: [35, 24]    
2025-01-17T14:14:12.252798Z DEBUG segment::index::hnsw_index::hnsw: building HNSW for 20448 vectors with 1 CPUs and GPU NVIDIA GeForce RTX    
2025-01-17T14:14:12.306838Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 8.383733ms    
2025-01-17T14:14:12.350022Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 43.149957ms    
2025-01-17T14:14:12.563229Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 3    
2025-01-17T14:14:12.567547Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 2    
2025-01-17T14:14:12.584357Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 1    
2025-01-17T14:14:12.704764Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 0    
2025-01-17T14:14:12.863544Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph patches time: 244.929076ms, count 48, avg 5.102689ms    
2025-01-17T14:14:12.863557Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph update entries time: 45.682864ms, count 116, avg 393.817µs    
2025-01-17T14:14:12.864267Z DEBUG segment::index::hnsw_index::hnsw: Finish main graph in time 609.504756ms    
2025-01-17T14:14:12.893944Z DEBUG segment::index::hnsw_index::hnsw: finish additional payload field indexing    
2025-01-17T14:14:33.538391Z DEBUG collection::update_handler: Optimizing segments: [39]    
2025-01-17T14:14:33.981678Z DEBUG segment::index::hnsw_index::hnsw: building HNSW for 10115 vectors with 1 CPUs and GPU NVIDIA GeForce RTX    
2025-01-17T14:14:34.042355Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 8.704221ms    
2025-01-17T14:14:34.085560Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 43.167577ms    
2025-01-17T14:14:34.316713Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 3    
2025-01-17T14:14:34.319841Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 2    
2025-01-17T14:14:34.323727Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 1    
2025-01-17T14:14:34.449390Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 0    
2025-01-17T14:14:34.630482Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph patches time: 264.045649ms, count 25, avg 10.561825ms    
2025-01-17T14:14:34.630494Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph update entries time: 41.552233ms, count 59, avg 704.275µs    
2025-01-17T14:14:34.630902Z DEBUG segment::index::hnsw_index::hnsw: Finish main graph in time 648.37273ms    
2025-01-17T14:14:34.646084Z DEBUG segment::index::hnsw_index::hnsw: finish additional payload field indexing    
2025-01-17T14:14:34.738732Z DEBUG collection::update_handler: Optimizing segments: [42, 41, 27]    
2025-01-17T14:14:35.428690Z DEBUG segment::index::hnsw_index::hnsw: building HNSW for 20805 vectors with 1 CPUs and GPU NVIDIA GeForce RTX    
2025-01-17T14:14:35.466226Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 8.516412ms    
2025-01-17T14:14:35.507628Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 41.364935ms    
2025-01-17T14:14:35.746082Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 3    
2025-01-17T14:14:35.748747Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 2    
2025-01-17T14:14:35.752229Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 1    
2025-01-17T14:14:35.766912Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 0    
2025-01-17T14:14:35.843282Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph patches time: 80.736269ms, count 50, avg 1.614725ms    
2025-01-17T14:14:35.843296Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph update entries time: 9.05213ms, count 118, avg 76.712µs    
2025-01-17T14:14:35.844014Z DEBUG segment::index::hnsw_index::hnsw: Finish main graph in time 413.806709ms    
2025-01-17T14:14:35.867328Z DEBUG segment::index::hnsw_index::hnsw: finish additional payload field indexing    
2025-01-17T14:14:56.539262Z DEBUG collection::update_handler: Optimizing segments: [47]    
2025-01-17T14:14:56.991738Z DEBUG segment::index::hnsw_index::hnsw: building HNSW for 10101 vectors with 1 CPUs and GPU NVIDIA GeForce RTX    
2025-01-17T14:14:57.029815Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 8.469982ms    
2025-01-17T14:14:57.071932Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 42.082562ms    
2025-01-17T14:14:57.302652Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 4    
2025-01-17T14:14:57.304762Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 3    
2025-01-17T14:14:57.306825Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 2    
2025-01-17T14:14:57.308378Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 1    
2025-01-17T14:14:57.315114Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 0    
2025-01-17T14:14:57.347453Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph patches time: 33.275342ms, count 25, avg 1.331013ms    
2025-01-17T14:14:57.347466Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph update entries time: 7.537926ms, count 80, avg 94.224µs    
2025-01-17T14:14:57.347865Z DEBUG segment::index::hnsw_index::hnsw: Finish main graph in time 355.23046ms    
2025-01-17T14:14:57.364990Z DEBUG segment::index::hnsw_index::hnsw: finish additional payload field indexing    
2025-01-17T14:14:57.461754Z DEBUG collection::update_handler: Optimizing segments: [50, 49, 34]    
2025-01-17T14:14:57.539063Z DEBUG collection::update_handler: Optimizing segments: [50, 49, 34]    
2025-01-17T14:14:58.149960Z DEBUG segment::index::hnsw_index::hnsw: building HNSW for 21052 vectors with 1 CPUs and GPU NVIDIA GeForce RTX    
2025-01-17T14:14:58.188532Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 9.201709ms    
2025-01-17T14:14:58.231230Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 42.657239ms    
2025-01-17T14:14:58.464677Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 3    
2025-01-17T14:14:58.467614Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 2    
2025-01-17T14:14:58.471709Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 1    
2025-01-17T14:14:58.486462Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 0    
2025-01-17T14:14:58.570162Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph patches time: 87.666589ms, count 51, avg 1.718952ms    
2025-01-17T14:14:58.570179Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph update entries time: 10.032284ms, count 121, avg 82.911µs    
2025-01-17T14:14:58.570954Z DEBUG segment::index::hnsw_index::hnsw: Finish main graph in time 419.280944ms    
2025-01-17T14:14:58.601255Z DEBUG segment::index::hnsw_index::hnsw: finish additional payload field indexing    
2025-01-17T14:15:20.539408Z DEBUG collection::update_handler: Optimizing segments: [55]    
2025-01-17T14:15:21.001468Z DEBUG segment::index::hnsw_index::hnsw: building HNSW for 10334 vectors with 1 CPUs and GPU NVIDIA GeForce RTX    
2025-01-17T14:15:21.047820Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 8.339833ms    
2025-01-17T14:15:21.090019Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 42.163242ms    
2025-01-17T14:15:21.325811Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 3    
2025-01-17T14:15:21.328505Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 2    
2025-01-17T14:15:21.331511Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 1    
2025-01-17T14:15:21.389388Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 0    
2025-01-17T14:15:21.514460Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph patches time: 152.516447ms, count 26, avg 5.866017ms    
2025-01-17T14:15:21.514474Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph update entries time: 29.699698ms, count 62, avg 479.027µs    
2025-01-17T14:15:21.514960Z DEBUG segment::index::hnsw_index::hnsw: Finish main graph in time 512.684925ms    
2025-01-17T14:15:21.536340Z DEBUG segment::index::hnsw_index::hnsw: finish additional payload field indexing    
2025-01-17T14:15:21.631734Z DEBUG collection::update_handler: Optimizing segments: [58, 57, 22]    
2025-01-17T14:15:22.343899Z DEBUG segment::index::hnsw_index::hnsw: building HNSW for 22014 vectors with 1 CPUs and GPU NVIDIA GeForce RTX    
2025-01-17T14:15:22.381473Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 8.312643ms    
2025-01-17T14:15:22.424414Z DEBUG segment::index::hnsw_index::gpu::shader_builder: Shader compilation took: 42.905638ms    
2025-01-17T14:15:22.659896Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 3    
2025-01-17T14:15:22.662496Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 2    
2025-01-17T14:15:22.666560Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 1    
2025-01-17T14:15:22.683323Z DEBUG segment::index::hnsw_index::gpu::gpu_graph_builder: Starting GPU level 0    
2025-01-17T14:15:22.766108Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph patches time: 86.449592ms, count 52, avg 1.662492ms    
2025-01-17T14:15:22.766122Z DEBUG segment::index::hnsw_index::gpu::gpu_insert_context: Gpu graph update entries time: 10.631021ms, count 124, avg 85.734µs    
2025-01-17T14:15:22.766915Z DEBUG segment::index::hnsw_index::hnsw: Finish main graph in time 421.505023ms    
2025-01-17T14:15:22.786583Z DEBUG segment::index::hnsw_index::hnsw: finish additional payload field indexing 
```
> It works without payload indexing.

Thank you very much, that's a good hint! Looking at the error it may even be a more generic error, not strictly related to GPU. In any case, we're onto it.

Thank you for giving GPU indexing a shot! 🔥 

Fix patch:
diff --git a/lib/gpu/src/context.rs b/lib/gpu/src/context.rs
index 0c32833a880..3784ad09b37 100644
--- a/lib/gpu/src/context.rs
+++ b/lib/gpu/src/context.rs
@@ -169,6 +169,10 @@ impl Context {
         dst_offset: usize,
         size: usize,
     ) -> GpuResult<()> {
+        if size == 0 {
+            return Ok(());
+        }
+
         if self.vk_command_buffer == vk::CommandBuffer::null() {
             self.init_command_buffer()?;
         }
@@ -201,6 +205,10 @@ impl Context {
 
     /// Clear buffer with zeros command. It records command to run it on GPU after `run` call.
     pub fn clear_buffer(&mut self, buffer: Arc<Buffer>) -> GpuResult<()> {
+        if buffer.size() == 0 {
+            return Ok(());
+        }
+
         if buffer.size() % std::mem::size_of::<u32>() != 0 {
             return Err(GpuError::OutOfBounds(
                 "Buffer size must be a multiple of `uint32` size to clear it".to_string(),
diff --git a/lib/segment/src/index/hnsw_index/gpu/batched_points.rs b/lib/segment/src/index/hnsw_index/gpu/batched_points.rs
index 4c6e4b5924c..d90c07c89fa 100644
--- a/lib/segment/src/index/hnsw_index/gpu/batched_points.rs
+++ b/lib/segment/src/index/hnsw_index/gpu/batched_points.rs
@@ -27,7 +27,7 @@ pub struct Batch<'a> {
 pub struct BatchedPoints {
     points: Vec<PointLinkingData>,
     batches: Vec<Range<usize>>,
-    first_point_id: PointOffsetType,
+    first_point_id: Option<PointOffsetType>,
     levels_count: usize,
     remap: Vec<PointOffsetType>,
 }
@@ -45,7 +45,11 @@ impl BatchedPoints {
             remap[*id as usize] = remapped_id as PointOffsetType;
         }
 
-        let first_point_id = ids.remove(0);
+        let first_point_id = if !ids.is_empty() {
+            Some(ids.remove(0))
+        } else {
+            None
+        };
 
         let batches = Self::build_initial_batches(&level_fn, &ids, groups_count);
 
@@ -57,7 +61,7 @@ impl BatchedPoints {
                 points.push(PointLinkingData {
                     point_id,
                     level,
-                    entry: first_point_id.into(),
+                    entry: first_point_id.unwrap_or_default().into(),
                 });
             }
         }
@@ -66,12 +70,14 @@ impl BatchedPoints {
             points,
             batches,
             first_point_id,
-            levels_count: level_fn(first_point_id) + 1,
+            levels_count: first_point_id
+                .map(|first_point_id| level_fn(first_point_id) + 1)
+                .unwrap_or_default(),
             remap,
         })
     }
 
-    pub fn first_point_id(&self) -> PointOffsetType {
+    pub fn first_point_id(&self) -> Option<PointOffsetType> {
         self.first_point_id
     }
 
diff --git a/lib/segment/src/index/hnsw_index/gpu/gpu_graph_builder.rs b/lib/segment/src/index/hnsw_index/gpu/gpu_graph_builder.rs
index a24703e6a37..1dc4101f451 100644
--- a/lib/segment/src/index/hnsw_index/gpu/gpu_graph_builder.rs
+++ b/lib/segment/src/index/hnsw_index/gpu/gpu_graph_builder.rs
@@ -57,18 +57,6 @@ pub fn build_hnsw_on_gpu<'a>(
         groups_count,
     )?;
 
-    // Create all GPU resources.
-    let mut gpu_search_context = GpuInsertContext::new(
-        gpu_vector_storage,
-        groups_count,
-        batched_points.remap(),
-        m,
-        m0,
-        ef,
-        exact,
-        1..MAX_VISITED_FLAGS_FACTOR,
-    )?;
-
     let graph_layers_builder =
         create_graph_layers_builder(&batched_points, num_vectors, m, m0, ef, entry_points_num);
 
@@ -90,9 +78,31 @@ pub fn build_hnsw_on_gpu<'a>(
         }
     }
 
+    // Check if all points are linked on CPU.
+    // If there are no batches left, we can return result before gpu resources creation.
+    if batched_points
+        .iter_batches(cpu_linked_points_count)
+        .next()
+        .is_none()
+    {
+        return Ok(graph_layers_builder);
+    }
+
+    // Create all GPU resources.
+    let mut gpu_search_context = GpuInsertContext::new(
+        gpu_vector_storage,
+        groups_count,
+        batched_points.remap(),
+        m,
+        m0,
+        ef,
+        exact,
+        1..MAX_VISITED_FLAGS_FACTOR,
+    )?;
+
     // Build all levels on GPU level by level.
     for level in (0..batched_points.levels_count()).rev() {
-        log::debug!("Starting GPU level {}", level,);
+        log::trace!("Starting GPU level {level}");
 
         gpu_search_context.upload_links(level, &graph_layers_builder, stopped)?;
         build_level_on_gpu(
@@ -236,4 +246,26 @@ mod tests {
 
         check_graph_layers_builders_quality(graph_layers_builder, test, top, ef, 0.8)
     }
+
+    #[test]
+    fn test_gpu_empty_hnsw() {
+        let _ = env_logger::builder()
+            .is_test(true)
+            .filter_level(log::LevelFilter::Trace)
+            .try_init();
+
+        let num_vectors = 0;
+        let dim = 64;
+        let m = 8;
+        let m0 = 16;
+        let ef = 32;
+        let groups_count = 4;
+        let searches_count = 20;
+        let min_cpu_linked_points_count = 64;
+
+        let test = create_gpu_graph_test_data(num_vectors, dim, m, m0, ef, searches_count);
+        let graph_layers_builder =
+            build_gpu_graph(&test, groups_count, min_cpu_linked_points_count, false);
+        assert!(graph_layers_builder.links_layers().is_empty());
+    }
 }
diff --git a/lib/segment/src/index/hnsw_index/gpu/gpu_vector_storage/gpu_multivectors.rs b/lib/segment/src/index/hnsw_index/gpu/gpu_vector_storage/gpu_multivectors.rs
index 397b98ec934..7b323750b66 100644
--- a/lib/segment/src/index/hnsw_index/gpu/gpu_vector_storage/gpu_multivectors.rs
+++ b/lib/segment/src/index/hnsw_index/gpu/gpu_vector_storage/gpu_multivectors.rs
@@ -129,7 +129,7 @@ impl GpuMultivectors {
             device.clone(),
             "Multivector offsets buffer",
             gpu::BufferType::Storage,
-            multivectors_count * std::mem::size_of::<GpuMultivectorOffset>(),
+            std::cmp::max(multivectors_count, 1) * std::mem::size_of::<GpuMultivectorOffset>(),
         )?;
         let offsets_staging_buffer = gpu::Buffer::new(
             device.clone(),
diff --git a/lib/segment/src/index/hnsw_index/gpu/gpu_vector_storage/gpu_quantization.rs b/lib/segment/src/index/hnsw_index/gpu/gpu_vector_storage/gpu_quantization.rs
index 0c8d7ec7e05..d205fa4474f 100644
--- a/lib/segment/src/index/hnsw_index/gpu/gpu_vector_storage/gpu_quantization.rs
+++ b/lib/segment/src/index/hnsw_index/gpu/gpu_vector_storage/gpu_quantization.rs
@@ -230,7 +230,7 @@ impl GpuScalarQuantization {
             device.clone(),
             "SQ offsets buffer",
             gpu::BufferType::Storage,
-            quantized_storage.vectors_count() * std::mem::size_of::<f32>(),
+            std::cmp::max(quantized_storage.vectors_count(), 1) * std::mem::size_of::<f32>(),
         )?;
 
         let sq_offsets_staging_buffer = gpu::Buffer::new(
@@ -349,7 +349,9 @@ impl GpuProductQuantization {
             device.clone(),
             "PQ vector division buffer",
             gpu::BufferType::Storage,
-            quantized_storage.get_metadata().vector_division.len() * std::mem::size_of::<u32>() * 2,
+            std::cmp::max(quantized_storage.get_metadata().vector_division.len(), 1)
+                * std::mem::size_of::<u32>()
+                * 2,
         )?;
         let vector_division_staging_buffer = gpu::Buffer::new(
             device.clone(),
diff --git a/lib/segment/src/index/hnsw_index/gpu/gpu_vector_storage/mod.rs b/lib/segment/src/index/hnsw_index/gpu/gpu_vector_storage/mod.rs
index 288aa7eb6f1..997ee66a526 100644
--- a/lib/segment/src/index/hnsw_index/gpu/gpu_vector_storage/mod.rs
+++ b/lib/segment/src/index/hnsw_index/gpu/gpu_vector_storage/mod.rs
@@ -137,13 +137,6 @@ impl GpuVectorStorage {
         force_half_precision: bool,
         stopped: &AtomicBool,
     ) -> OperationResult<Self> {
-        // GPU buffers should not be empty.
-        // Check that we have enough vectors to store at least one vector in each buffer.
-        if vector_storage.total_vector_count() < STORAGES_COUNT {
-            return Err(OperationError::service_error(
-                "Vectors count is less than `STORAGES_COUNT`",
-            ));
-        }
         if let Some(quantized_storage) = quantized_storage {
             Self::new_quantized(
                 device,
@@ -557,7 +550,7 @@ impl GpuVectorStorage {
                     device.clone(),
                     "Vector storage buffer",
                     gpu::BufferType::Storage,
-                    points_in_storage_count * gpu_vector_size,
+                    std::cmp::max(points_in_storage_count, 1) * gpu_vector_size,
                 )
             })
             .collect::<gpu::GpuResult<Vec<_>>>()?;
@@ -576,7 +569,7 @@ impl GpuVectorStorage {
             device.clone(),
             "Vector storage upload staging buffer",
             gpu::BufferType::CpuToGpu,
-            upload_points_count * gpu_vector_size,
+            std::cmp::max(upload_points_count, 1) * gpu_vector_size,
         )?;
         // fill staging buffer with zeros
         let zero_vector = vec![TElement::default(); gpu_vector_capacity];
diff --git a/lib/segment/src/index/hnsw_index/gpu/mod.rs b/lib/segment/src/index/hnsw_index/gpu/mod.rs
index 45e999735a7..22dc942fa0f 100644
--- a/lib/segment/src/index/hnsw_index/gpu/mod.rs
+++ b/lib/segment/src/index/hnsw_index/gpu/mod.rs
@@ -71,25 +71,20 @@ fn create_graph_layers_builder(
     // mark all vectors as ready
     graph_layers_builder.clear_ready_list();
 
-    // set first entry point
-    graph_layers_builder.set_levels(
-        batched_points.first_point_id(),
-        batched_points.levels_count() - 1,
-    );
-    graph_layers_builder.get_entry_points().new_point(
-        batched_points.first_point_id(),
-        batched_points.levels_count() - 1,
-        |_| true,
-    );
-
-    // set levels
-    graph_layers_builder.set_levels(
-        batched_points.first_point_id(),
-        batched_points.levels_count() - 1,
-    );
-    for batch in batched_points.iter_batches(0) {
-        for linking_point in batch.points {
-            graph_layers_builder.set_levels(linking_point.point_id, batch.level);
+    if let Some(first_point_id) = batched_points.first_point_id() {
+        // set first entry point
+        graph_layers_builder.get_entry_points().new_point(
+            first_point_id,
+            batched_points.levels_count() - 1,
+            |_| true,
+        );
+
+        // set levels
+        graph_layers_builder.set_levels(first_point_id, batched_points.levels_count() - 1);
+        for batch in batched_points.iter_batches(0) {
+            for linking_point in batch.points {
+                graph_layers_builder.set_levels(linking_point.point_id, batch.level);
+            }
         }
     }
 


Test patch: