GetBuilder Error

Description

Im experimenting with the vector similarity search specifically search with a vector and i got this error on my console :

{“error”:“‘GetBuilder’ object has no attribute ‘with_additional’”}

What is the root cause for this issue and how can i fix it

This is the schema that i defined and the function that runs it

def create_schema():
    schema = {
        "classes": [
            {
                "class": "Embeddings",
                "vectorizer": "none", 
                "properties": [
                    {
                        "name": "chunk",
                        "dataType": ["text"]
                    }
                ]
            }
        ]
    }
    client.schema.create(schema)

and this is the endpoint that saves the vectors in the weaviate db

def save_vectorstore(chunks):
    try:
        embeddings_model = pipeline('feature-extraction', model='bert-base-uncased')
        for chunk in chunks:
            embeddings = embeddings_model(chunk)
            vector = embeddings[0][0]
            data_object = {
                "text": chunk
            }
            client.data_object.create(class_name="Embeddings", data_object=data_object, vector=vector)
        return {"message": "Vector store saved successfully"}
    except Exception as e:
        return {'error': str(e)}

Thanks for your help in advance !!!

Additional Information

What im trying to build is a vector database that contains vectors from chunks of text that i got from my document(s), im using it in a chatapp to figure out from a user’s prompt what to reply with for the assistant that im using; I don’t know if i got the schema right and if there any suggestions to improve it for this case I’ll appreciate it.

hi @Hamza_Rezgui !!

Welcome to our community :hugs:

Any reason why you are using python v3? Python v4 is way better. Not only on the syntax, but specially in performance.

let me know if you need help on migrating to pyv4.
here we have a guide that cover this migration:

This error message doesn’t seems related to inserting objects, but querying. GetBuilder

Can you paste the full traceback of this error?

Thanks!

Hi @DudaNogueira , So i tried migrating to v4 and im using a docker container, i instanciated the client with
client = weaviate.connect_to_local()
and i got this whole block of error

Traceback (most recent call last):
File “/usr/src/app/venv/bin/flask”, line 8, in
sys.exit(main())
^^^^^^
File “/usr/src/app/venv/lib/python3.11/site-packages/flask/cli.py”, line 1105, in main
cli.main()
File “/usr/src/app/venv/lib/python3.11/site-packages/click/core.py”, line 1078, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File “/usr/src/app/venv/lib/python3.11/site-packages/click/core.py”, line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/app/venv/lib/python3.11/site-packages/click/core.py”, line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/app/venv/lib/python3.11/site-packages/click/core.py”, line 783, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/app/venv/lib/python3.11/site-packages/click/decorators.py”, line 92, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/app/venv/lib/python3.11/site-packages/click/core.py”, line 783, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/app/venv/lib/python3.11/site-packages/flask/cli.py”, line 953, in run_command
raise e from None
File “/usr/src/app/venv/lib/python3.11/site-packages/flask/cli.py”, line 937, in run_command
app: WSGIApplication = info.load_app()
^^^^^^^^^^^^^^^
File “/usr/src/app/venv/lib/python3.11/site-packages/flask/cli.py”, line 335, in load_app
app = locate_app(import_name, name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/app/venv/lib/python3.11/site-packages/flask/cli.py”, line 245, in locate_app
import(module_name)
File “/usr/src/app/app.py”, line 2, in
from endpoints import endpoints_bp
File “/usr/src/app/endpoints.py”, line 2, in
from utils import extract_text, save_vectorstore, similarity_search
File “/usr/src/app/utils.py”, line 12, in
client = weaviate.connect_to_local()
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/app/venv/lib/python3.11/site-packages/weaviate/connect/helpers.py”, line 213, in connect_to_local
return __connect(client)
^^^^^^^^^^^^^^^^^
File “/usr/src/app/venv/lib/python3.11/site-packages/weaviate/connect/helpers.py”, line 401, in __connect
raise e
File “/usr/src/app/venv/lib/python3.11/site-packages/weaviate/connect/helpers.py”, line 397, in __connect
client.connect()
File “/usr/src/app/venv/lib/python3.11/site-packages/weaviate/client.py”, line 287, in connect
self._connection.connect(self.__skip_init_checks)
File “/usr/src/app/venv/lib/python3.11/site-packages/weaviate/connect/v4.py”, line 711, in connect
super().connect(skip_init_checks)
File “/usr/src/app/venv/lib/python3.11/site-packages/weaviate/connect/v4.py”, line 138, in connect
self._create_clients(self._auth, skip_init_checks)
File “/usr/src/app/venv/lib/python3.11/site-packages/weaviate/connect/v4.py”, line 260, in _create_clients
raise WeaviateConnectionError(
weaviate.exceptions.WeaviateConnectionError: Connection to Weaviate failed. Error: [Errno 111] Connection refused.
Is Weaviate running and reachable at http://localhost:8080?

i just want to know how can i instantiate it exactly while using docker and thank you
ps : when i access localhost:8080/v1, it gives me all these documentation hrefs but nothing when the path is just localhost:8080.

hi @Hamza_Rezgui !

Is your application running side by side by the Weaviate server inside docker?

If that’s the case, you need to point your client like so:

client = weaviate.connect_to_local(host="weaviate")

edit: host should be a string.

Otherwise the python client will try to connect on it’s own cluster, where there is no Weaviate server running.

Let me know if this helps!

THanks!

hi @DudaNogueira!
Im running my flask app also on docker and this is its docker compose service definition

flask-app:
    image: python:3.11-slim
    ports:
      - "5000:5000"
    volumes:
      - "${FLASK_PATH_PROJECT}:/usr/src/app"
    working_dir: /usr/src/app
    environment:
      FLASK_APP: app.py
      FLASK_ENV: development
    command: bash -c "python -m venv venv && source venv/bin/activate && pip install --no-cache-dir -r requirements.txt && flask run --host=0.0.0.0"
    depends_on:
      - weaviate

using client = weaviate.connect_to_local(host=weaviate) didnt help and it gave me this error now

Traceback (most recent call last):
File “/usr/src/app/venv/bin/flask”, line 8, in
sys.exit(main())
^^^^^^
File “/usr/src/app/venv/lib/python3.11/site-packages/flask/cli.py”, line 1105, in main
cli.main()
File “/usr/src/app/venv/lib/python3.11/site-packages/click/core.py”, line 1078, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File “/usr/src/app/venv/lib/python3.11/site-packages/click/core.py”, line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/app/venv/lib/python3.11/site-packages/click/core.py”, line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/app/venv/lib/python3.11/site-packages/click/core.py”, line 783, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/app/venv/lib/python3.11/site-packages/click/decorators.py”, line 92, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/app/venv/lib/python3.11/site-packages/click/core.py”, line 783, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/app/venv/lib/python3.11/site-packages/flask/cli.py”, line 953, in run_command
raise e from None
File “/usr/src/app/venv/lib/python3.11/site-packages/flask/cli.py”, line 937, in run_command
app: WSGIApplication = info.load_app()
^^^^^^^^^^^^^^^
File “/usr/src/app/venv/lib/python3.11/site-packages/flask/cli.py”, line 335, in load_app
app = locate_app(import_name, name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/app/venv/lib/python3.11/site-packages/flask/cli.py”, line 245, in locate_app
import(module_name)
File “/usr/src/app/app.py”, line 2, in
from endpoints import endpoints_bp
File “/usr/src/app/endpoints.py”, line 2, in
from utils import extract_text, save_vectorstore, similarity_search
File “/usr/src/app/utils.py”, line 12, in
client = weaviate.connect_to_local(host=weaviate)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/app/venv/lib/python3.11/site-packages/weaviate/connect/helpers.py”, line 205, in connect_to_local
http=ProtocolParams(host=host, port=port, secure=False),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/app/venv/lib/python3.11/site-packages/pydantic/main.py”, line 176, in init
self.pydantic_validator.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 1 validation error for ProtocolParams
host
Input should be a valid string [type=string_type, input_value=<module ‘weaviate’ from ‘…s/weaviate/init.py’>, input_type=module]
For further information visit Redirecting...

Ooops.

the host should be weaviate as a string.

so

client = weaviate.connect_to_local(host="weaviate")

this failed as it was passing the weaviate module itself as the host :grimacing:

Let me know if this works.

This is because your app will now connect to the container “weaviate” that is a hostname available inside your docker-compose, based on the name of the services :slight_smile:

hi @DudaNogueira! this is the right one thank you so much for your assistance !
One final question if you don’t mind, Im using an embedding model from hugging face through the pipeline method and i was wondering which one is the best to use so i can store the vectors in the weaviate database ?

1 Like

Hi!

It will depend. Using this integration/module will give you the advantage of not worrying with vectorizing your content both to ingest and search.

If you ever change any of the fields marked to be vectorized, Weaviate will automatically vectorize your updated object.

If you go the pipeline route (or ingesting/updating the vectors yourself), you will need to always vectorize you data.

Let me know if this helps :slight_smile:

Thanks!