hnswlib icon indicating copy to clipboard operation
hnswlib copied to clipboard

Windows fatal exception: access violation

Open Enquandriant opened this issue 7 months ago • 0 comments

Hi, I am trying to use this and can't even get the simplest of example code to work. I have a python environment created with conda

conda create -n "310" python=3.10

with numpy and hnswlib installed by

pip install hnswlib numpy

trying to run this test script

import hnswlib
import numpy as np
import faulthandler
import sys
import os

faulthandler.enable()

print(f"Python version: {sys.version}")
print(f"Process ID: {os.getpid()}")
print(f"numpy version: {np.__version__}")
print(f"hnswlib: {hnswlib}")

dim = 2
num_elements = 3
data = np.float32(np.random.random((num_elements, dim)))
ids = np.arange(num_elements)

print("Data:")
print(data)
print("IDs:")
print(ids)

try:
    p = hnswlib.Index(space='l2', dim=dim)  # possible options are l2, cosine or ip
    p.init_index(max_elements=num_elements + 10, ef_construction=100, M=8)
    p.add_items(data, ids)
    print("Insertion complete!")
except Exception as e:
    print(f"An error occurred: {e}")

with the following output

(310) C:\Users\User> python test.py
Python version: 3.10.14 | packaged by Anaconda, Inc. | (main, May  6 2024, 19:44:50) [MSC v.1916 64 bit (AMD64)]
Process ID: 14284
numpy version: 2.0.0
hnswlib: <module 'hnswlib' from 'C:\\Users\\User\\miniconda3\\envs\\310\\lib\\site-packages\\hnswlib.cp310-win_amd64.pyd'>
Data:
[[0.35375407 0.4176661 ]
 [0.8533985  0.15651907]
 [0.3862144  0.612005  ]]
IDs:
[0 1 2]
Windows fatal exception: access violation

Current thread 0x000057a4 (most recent call first):
  File "C:\Users\User\test.py", line 27 in <module>

noting that line 27 is

    p.add_items(data, ids)

It crashes every time I try to add any data to the index. Any advice/ideas?

Enquandriant avatar Jun 27 '24 23:06 Enquandriant