Description
With python V3 client, we can use the following to add a new property to a collection:
client.schema.property.create(collection_name, prop)
How can we do the same with V4 client?
With python V3 client, we can use the following to add a new property to a collection:
client.schema.property.create(collection_name, prop)
How can we do the same with V4 client?
Hi, you can do
collection.config.add_property(Property(name="name", data_type=DataType.TEXT))
Hi Dirk, does this have any conflict with what is mentioned below:
Adding a property after importing objects can lead to limitations in inverted-index related behavior, such as filtering by the new property’s length or null status.
This is caused by the inverted index being built at import time. If you add a property after importing objects, the inverted index for metadata such as the length or the null status will not be updated to include the new properties. This means that the new property will not be indexed for existing objects. This can lead to unexpected behavior when querying.
To avoid this, you can either:
- Add the property before importing objects.
- Delete the collection, re-create it with the new property and then re-import the data.
We are working on a re-indexing API to allow you to re-index the data after adding a property. This will be available in a future release.
hi @abdimussa !!
If you add a property to a previously created collection that had the inverted index to index null state and property length, then yes.
Here you have the python code to create such a collection:
By default, those configs are off.
Here is how to check the default inverted index config of a collection:
client.collections.delete("Test")
collection = client.collections.create(
"Test",
)
collection.config.get().inverted_index_config.to_dict()
this should output:
{'bm25': {'b': 0.75, 'k1': 1.2},
'cleanupIntervalSeconds': 60,
'indexNullState': False,
'indexPropertyLength': False,
'indexTimestamps': False,
'stopwords': {'preset': 'en'}}
Let me know if this helps!
Thanks!
Thank you @DudaNogueira, it is now clear. One question I have though is, what is the purpose of having those set to True.
Hi!
indexNullState=True
will create an index for the fields that doesn’t have it. So let’s say you have 10 objects, 4 with the property colors
set to something, and 6 that doesn’t have a colors
property.
If you set indexNullState to True, you will be able to filter objects that has nothing set as has_color
. Here is the section of the docs about it
The same goes to indexPropertyLength, (more info here) that will allow you to filter by that value, as described here.
And similarly, you can set indexTimestamps, as described here
Let me know if that helps!
Thanks!
@DudaNogueira this definitely helps. Thank you. Regarding the indexTimestamps, I got an answer that I need to recreate the collection in order to change its value, and had a question about it here Filtering based on creation_time requires index_timestamps - Support - Weaviate Community Forum.
I would appreciate it if you can help. Thank you