Skip to content

Unpinned numpy breaks vectorcode on Mac OS #6

@kwrobert

Description

@kwrobert

When following the installation instructions for the vectorcode CLI on my Mac OS environment, vectorcode does not work. If I downgrade numpy to numpy==1.26.4 it fixes the issue.

Details of my environment:

OS: Mac OS 14.7.3 (23H417)
Python: 3.12.7
pipx version: 1.7.1
pip version: 24.1.2

Here is the error I get with the default installation:

$ vectorcode vectorise ./lua/codecompanion/init.lua
Host at 127.0.0.1:8000 is unavailable. VectorCode will start its own Chromadb at a random port.
Creating database at /Users/kyle/.local/share/vectorcode/chromadb/.

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.2.3 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.

If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.

Traceback (most recent call last):  File "/Users/kyle/.local/bin/vectorcode", line 8, in <module>
    sys.exit(main())
  File "/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/vectorcode/main.py", line 90, in main
    return asyncio.run(async_main())
  File "/Users/kyle/.local/share/mise/installs/python/3.12.9/lib/python3.12/asyncio/runners.py", line 195, in run
    return runner.run(main)
  File "/Users/kyle/.local/share/mise/installs/python/3.12.9/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
  File "/Users/kyle/.local/share/mise/installs/python/3.12.9/lib/python3.12/asyncio/base_events.py", line 678, in run_until_complete
    self.run_forever()
  File "/Users/kyle/.local/share/mise/installs/python/3.12.9/lib/python3.12/asyncio/base_events.py", line 645, in run_forever
    self._run_once()
  File "/Users/kyle/.local/share/mise/installs/python/3.12.9/lib/python3.12/asyncio/base_events.py", line 1999, in _run_once
    handle._run()
  File "/Users/kyle/.local/share/mise/installs/python/3.12.9/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/vectorcode/main.py", line 70, in async_main
    return_val = await vectorise(final_configs)
  File "/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/vectorcode/subcommands/vectorise.py", line 87, in vectorise
    collection = await make_or_get_collection(client, configs)
  File "/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/vectorcode/common.py", line 141, in make_or_get_collection
    embedding_function=get_embedding_function(configs),
  File "/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/vectorcode/common.py", line 116, in get_embedding_function
    return getattr(embedding_functions, configs.embedding_function)(
  File "/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/chromadb/utils/embedding_functions/sentence_transformer_embedding_function.py", line 32, in __init__
    from sentence_transformers import SentenceTransformer
  File "/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/sentence_transformers/__init__.py", line 9, in <module>
    from sentence_transformers.backend import (
  File "/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/sentence_transformers/backend.py", line 11, in <module>
    from sentence_transformers.util import disable_datasets_caching, is_datasets_available
  File "/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/sentence_transformers/util.py", line 17, in <module>
    import torch
  File "/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/torch/__init__.py", line 1477, in <module>
    from .functional import *  # noqa: F403
  File "/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/torch/functional.py", line 9, in <module>
    import torch.nn.functional as F
  File "/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/torch/nn/__init__.py", line 1, in <module>
    from .modules import *  # noqa: F403
  File "/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/torch/nn/modules/__init__.py", line 35, in <module>
    from .transformer import TransformerEncoder, TransformerDecoder, \
  File "/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/torch/nn/modules/transformer.py", line 20, in <module>
    device: torch.device = torch.device(torch._C._get_default_device()),  # torch.device('cpu'),
/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/torch/nn/modules/transformer.py:20: UserWarning: Failed to initialize NumPy: _ARRAY_API not found (Triggered internally at /Users/runner/work/pytorch/pytorch/pytorch/torch/csrc/utils/tensor_numpy.cpp:84.)
  device: torch.device = torch.device(torch._C._get_default_device()),  # torch.device('cpu'),
Vectorising files...:   0%|                                                                                                                                                                               | 0/1 [00:01<?, ?it/s]
Traceback (most recent call last):
  File "/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/chromadb/api/models/CollectionCommon.py", line 90, in wrapper
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/chromadb/api/models/CollectionCommon.py", line 213, in _validate_and_prepare_add_request
    add_embeddings = self._embed_record_set(record_set=add_records)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/chromadb/api/models/CollectionCommon.py", line 526, in _embed_record_set
    return self._embed(input=record_set[field])  # type: ignore[literal-required]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/chromadb/api/models/CollectionCommon.py", line 539, in _embed
    return self._embedding_function(input=input)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/chromadb/api/types.py", line 466, in __call__
    result = call(self, input)
             ^^^^^^^^^^^^^^^^^
  File "/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/chromadb/utils/embedding_functions/sentence_transformer_embedding_function.py", line 48, in __call__
    for embedding in self._model.encode(
                     ^^^^^^^^^^^^^^^^^^^
  File "/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/sentence_transformers/SentenceTransformer.py", line 674, in encode
    all_embeddings = np.asarray([emb.numpy() for emb in all_embeddings])
                                 ^^^^^^^^^^^
RuntimeError: Numpy is not available

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/vectorcode/main.py", line 70, in async_main
    return_val = await vectorise(final_configs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/vectorcode/subcommands/vectorise.py", line 130, in vectorise
    await task
  File "/Users/kyle/.local/share/mise/installs/python/3.12.9/lib/python3.12/asyncio/tasks.py", line 631, in _wait_for_one
    return f.result()  # May raise f.exception().
           ^^^^^^^^^^
  File "/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/vectorcode/subcommands/vectorise.py", line 62, in chunked_add
    await collection.add(
  File "/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/chromadb/api/models/AsyncCollection.py", line 63, in add
    add_request = self._validate_and_prepare_add_request(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/chromadb/api/models/CollectionCommon.py", line 93, in wrapper
    raise type(e)(msg).with_traceback(e.__traceback__)
  File "/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/chromadb/api/models/CollectionCommon.py", line 90, in wrapper
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/chromadb/api/models/CollectionCommon.py", line 213, in _validate_and_prepare_add_request
    add_embeddings = self._embed_record_set(record_set=add_records)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/chromadb/api/models/CollectionCommon.py", line 526, in _embed_record_set
    return self._embed(input=record_set[field])  # type: ignore[literal-required]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/chromadb/api/models/CollectionCommon.py", line 539, in _embed
    return self._embedding_function(input=input)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/chromadb/api/types.py", line 466, in __call__
    result = call(self, input)
             ^^^^^^^^^^^^^^^^^
  File "/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/chromadb/utils/embedding_functions/sentence_transformer_embedding_function.py", line 48, in __call__
    for embedding in self._model.encode(
                     ^^^^^^^^^^^^^^^^^^^
  File "/Users/kyle/.local/pipx/venvs/vectorcode/lib/python3.12/site-packages/sentence_transformers/SentenceTransformer.py", line 674, in encode
    all_embeddings = np.asarray([emb.numpy() for emb in all_embeddings])
                                 ^^^^^^^^^^^
RuntimeError: Numpy is not available in add.
vectorcode vectorise ./lua/codecompanion/init.lua  8.15s user 2.30s system 14% cpu 1:10.72 total

If I downgrade numpy in the pipx virtualenv via: pipx runpip vectorcode install numpy==1.26.4

Then everything works:

ectorcode vectorise ./lua/codecompanion/init.lua
Host at 127.0.0.1:8000 is unavailable. VectorCode will start its own Chromadb at a random port.
Creating database at /Users/kyle/.local/share/vectorcode/chromadb/.
Vectorising files...: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:01<00:00,  1.68s/it]
  Added    Updated    Removed
-------  ---------  ---------
      1          0          0
vectorcode vectorise ./lua/codecompanion/init.lua  9.85s user 3.18s system 56% cpu 23.140 total

I suspect pinning numpy in the pyproject.toml file for this repo will fix the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions