postgresml / korvus

Korvus is a search SDK that unifies the entire RAG pipeline in a single database query. Built on top of Postgres with bindings for Python, JavaScript, Rust and C.
https://postgresml.org
MIT License
1.27k stars 24 forks source link

Exception: error returned from database: invalid input value for enum task: "embedding" #10

Closed fahdmirza closed 4 months ago

fahdmirza commented 4 months ago

Hi, I have installed the postgres as per your getting started guide and then followed the instructins in read me and getting following error:

asyncio.run(add_pipeline()) Traceback (most recent call last): File "", line 1, in File "/home/Ubuntu/miniconda3/envs/korvus/lib/python3.11/asyncio/runners.py", line 190, in run return runner.run(main) ^^^^^^^^^^^^^^^^ File "/home/Ubuntu/miniconda3/envs/korvus/lib/python3.11/asyncio/runners.py", line 118, in run return self._loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/Ubuntu/miniconda3/envs/korvus/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "", line 2, in add_pipeline Exception: error returned from database: invalid input value for enum task: "embedding"

Steps I followed:

conda create -n korvus python=3.11 -y && conda activate korvus

docker run \ -it \ -v postgresml_data:/var/lib/postgresql \ --gpus all \ -p 5433:5432 \ -p 8000:8000 \ ghcr.io/postgresml/postgresml:2.7.3 \ sudo -u postgresml psql -d postgresml

pip install korvus

export KORVUS_DATABASE_URL="postgresql://postgresml:post@localhost:5433/postgresml"

SilasMarvin commented 4 months ago

Can you share the code you are running?

fahdmirza commented 4 months ago

Can you share the code you are running?

I shared it above already with all the steps. Its from your git repo.

SilasMarvin commented 4 months ago

Can you share the code you are running?

I shared it above already with all the steps. Its from your git repo.

If you are running the code from the GitHub repo README and getting that error I'm guessing we have an outdated migration in our docker container. If you want to use it for now I would recommend signing up on our site. You get a free $100 which goes a long way. In the meantime I will investigate the docker container.

fahdmirza commented 4 months ago

Could I request you to please update the repo with this information as I battled with it for the last 3 hours. Also your cloud offering asks for payment option, which I am not comfortable providing. Anyway, thanks for the help.

SilasMarvin commented 4 months ago

This repo is agnostic to PostgresML's repo. You don't need to use docker to work with it that is one option. You can run Postgres yourself and install the pgml and pgvector extensions separately. Closing this issue as its not something to be fixed in this repo but I'll look into it.

RyanGreenup commented 4 months ago

I too was getting that issue, but I noticed in the postgresml documentation that there are two versions specified:

docker-compose.yml

 version: '3.9'
services:
    postgresml:
        image: 'ghcr.io/postgresml/postgresml:2.7.13'
        command: tail -f /dev/null
        ports:
            - '8000:8000'
            - '5433:5432'
#       I couldn't get this to work for some reason, for now doesn't matter
#       volumes:
#         - './data/postgresql:/var/lib/postgresql'
        tty: true
        stdin_open: true
        deploy:
            resources:
              reservations:
                devices:
                  - driver: nvidia
                    device_ids: ['0', '1']
                 #  device_ids: ['0']
                    capabilities: [gpu]

However, I couldn't run the example in the README.md Because it requires trust_remote_code=True, and I'm not sure where to set it (for reference it takes me about 2 minutes before it hit that):

collection = Collection("korvus-demo-v0")
pipeline = Pipeline(
    "v1",
    {
        "text": {
            "splitter": {"model": "recursive_character"},
            "semantic_search": {"model": "Alibaba-NLP/gte-base-en-v1.5"},
        }
    },
)
**Traceback** ``` Traceback (most recent call last): File "/tmp/tmp.GzKWU2ac8y/main2.py", line 20, in asyncio.run(add_pipeline()) File "/usr/lib/python3.12/asyncio/runners.py", line 194, in run return runner.run(main) ^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/asyncio/runners.py", line 118, in run return self._loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "/tmp/tmp.GzKWU2ac8y/main2.py", line 17, in add_pipeline await collection.add_pipeline(pipeline) Exception: error returned from database: Traceback (most recent call last): File "", line 272, in embed File "", line 247, in create_embedding File "/var/lib/postgresml-python/pgml-venv/lib/python3.10/site-packages/sentence_transformers/SentenceTransformer.py", line 95, in __init__ modules = self._load_sbert_model(model_path) File "/var/lib/postgresml-python/pgml-venv/lib/python3.10/site-packages/sentence_transformers/SentenceTransformer.py", line 840, in _load_sbert_model module = module_class.load(os.path.join(model_path, module_config['path'])) File "/var/lib/postgresml-python/pgml-venv/lib/python3.10/site-packages/sentence_transformers/models/Transformer.py", line 137, in load return Transformer(model_name_or_path=input_path, **config) File "/var/lib/postgresml-python/pgml-venv/lib/python3.10/site-packages/sentence_transformers/models/Transformer.py", line 28, in __init__ config = AutoConfig.from_pretrained(model_name_or_path, **model_args, cache_dir=cache_dir) File "/var/lib/postgresml-python/pgml-venv/lib/python3.10/site-packages/transformers/models/auto/configuration_auto.py", line 1037, in from_pretrained trust_remote_code = resolve_trust_remote_code( File "/var/lib/postgresml-python/pgml-venv/lib/python3.10/site-packages/transformers/dynamic_module_utils.py", line 608, in resolve_trust_remote_code raise ValueError( ValueError: The repository for /var/lib/postgresql/.cache/torch/sentence_transformers/Alibaba-NLP_gte-base-en-v1.5/ contains custom code which must be executed to correctlyload the model. You can inspect the repository content at https://hf.co//var/lib/postgresql/.cache/torch/sentence_transformers/Alibaba-NLP_gte-base-en-v1.5/. Please pass the argument `trust_remote_code=True` to allow custom code to be run. ```

Next I tried the Example app for Semantic Search, after 10 minutes I hit an unexpected keyword error, so perhaps the versions do matter :shrug:

KORVUS_DATABASE_URL=postgresql://postgresml@localhost:5433 python main.py
`main.py` ```python from korvus import Collection, Pipeline from rich import print import asyncio # Initialize our Collection collection = Collection("semantic-search-demo") # Initialize our Pipeline # Our Pipeline will split and embed the `text` key of documents we upsert pipeline = Pipeline( "v1", { "text": { "splitter": {"model": "recursive_character"}, "semantic_search": { "model": "mixedbread-ai/mxbai-embed-large-v1", }, }, }, ) async def main(): # Add our Pipeline to our Collection await collection.add_pipeline(pipeline) # Upsert our documents # The `text` key of our documents will be split and embedded per our Pipeline specification above documents = [ { "id": "1", "text": "Korvus is incredibly fast and easy to use.", }, { "id": "2", "text": "Tomatoes are incredible on burgers.", }, ] await collection.upsert_documents(documents) # Perform vector_search # We are querying for the string "Is Korvus fast?" # Notice that the `mixedbread-ai/mxbai-embed-large-v1` embedding model takes a prompt paramter when embedding for search # We specify that we only want to return the `id` of documents. If the `document` key was blank it would return the entire document with every result # Limit the results to 5. In our case we only have two documents in our Collection so we will only get two results results = await collection.vector_search( { "query": { "fields": { "text": { "query": "Is Korvus fast?", "parameters": { "prompt": "Represent this sentence for searching relevant passages: ", }, }, }, }, "document": {"keys": ["id"]}, "limit": 5, }, pipeline, ) print(results) asyncio.run(main()) ```
**Traceback** ``` Traceback (most recent call last): File "/tmp/tmp.GzKWU2ac8y/main.py", line 66, in asyncio.run(main()) File "/usr/lib/python3.12/asyncio/runners.py", line 194, in run return runner.run(main) ^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/asyncio/runners.py", line 118, in run return self._loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "/tmp/tmp.GzKWU2ac8y/main.py", line 25, in main await collection.add_pipeline(pipeline) Exception: error returned from database: Traceback (most recent call last): File "", line 272, in embed File "", line 247, in create_embedding File "/var/lib/postgresml-python/pgml-venv/lib/python3.10/site-packages/sentence_transformers/SentenceTransformer.py", line 95, in __init__ modules = self._load_sbert_model(model_path) File "/var/lib/postgresml-python/pgml-venv/lib/python3.10/site-packages/sentence_transformers/SentenceTransformer.py", line 840, in _load_sbert_model module = module_class.load(os.path.join(model_path, module_config['path'])) File "/var/lib/postgresml-python/pgml-venv/lib/python3.10/site-packages/sentence_transformers/models/Pooling.py", line 120, in load return Pooling(**config) TypeError: Pooling.__init__() got an unexpected keyword argument 'pooling_mode_weightedmean_tokens' ```
montanalow commented 4 months ago

trust_remote_code is now supported in the master branch of pgml, although we haven't released new docker images yet.