Description
I have multi-tenancy enabled on a collection, and I’m trying to import a chunk of objects into it.
I’m also trying to use the new automatic tenant creation. Can’t figure out why I’m getting this error.
Using a free sandbox running 1.25.1 and the 4.6.3 Python client.
I create the collection like this:
with weaviate.connect_to_wcs(host, api_key) as client:
config = Configure.multi_tenancy(enabled=True, auto_tenant_creation=True)
collection: Collection = client.collections.create(COLLECTION_ID, multi_tenancy_config=config)
With WCS, I can verify this succeeds and multi-tenancy is enabled.
Then when importing:
collection: Collection = client.collections.get(COLLECTION_ID).with_tenant(FB_USER_ID)
#...
try:
with collection.batch.fixed_size(batch_size = limit, concurrent_requests = 1) as batch:
#...
batch.add_object(properties=properties, vector=embedding, uuid=uuid)
And that fails on multiple adds with:
[ErrorObject(message='tenant not found: "2411369"', object_=_BatchObject(collection='Document', vector=[-0.003025880316272378, ...
(FB_USER_ID is 2411369, i.e. the ID makes sense).
And I get this same error if I skip the with_tenant(FB_USER_ID)
fragment above.
Using a free sandbox running 1.25.1 and the 4.6.3 Python client.
hi @nikolay !
I am afraid that feature is only available on client level batch operations.
Here, for example:
# lets import data in batch to newly created tenants
data = [
{"tenant": "tenant1", "text": "Text for tenant1"},
{"tenant": "tenant2", "text": "Text for tenant2"},
]
with client.batch.fixed_size(batch_size=200) as batch:
for obj in data:
properties = {
"text": obj["text"],
}
batch.add_object(
collection="CollectionWithAutoMTEnabled",
properties=properties,
tenant=obj["tenant"],
)
I took this opportunity and played with this feature myself.
Here you can find a recipe on that:
Let me know if this helps.
Thanks!
Hey, thanks! That’s not actually what I’m seeing.
I did discover, however, that passing in a Tenant object into the Python client does make my code work, at either the collection or client batch level. It’s ostensibly typed to also work with a straight string per my code sample above, but for some reason, it errors.
Next, another, possibly independent, issue: I can’t fetch what I’ve imported with the WCS GraphQL query UI, and the error is also about the missing tenant:
{
Get {
Document(
limit: 20,
tenant:"2411369"
) {
document_id
text
}
}
}
Result:
{
"data": {
"Get": {
"Document": null
}
},
"errors": [
{
"locations": [
{
"column": 5,
"line": 3
}
],
"message": "explorer: list class: search: object search at index document: tenant not found: \"2411369\"",
"path": [
"Get",
"Document"
]
}
]
}
I also tried stuff like “name:2411369” and “tenant:2411369”. I bet something like that’s going on.
And today getting the same errors regardless of whether I use a client level batch or collection level. Super weird. Going to try provisioning a real box and looking at the server logs.
Auto tenant with single insert is now supported in 1.25.2.
This version should be available in our cloud soon.
I have updated the aforementioned recipe:
# create tenant also from single inserts
tenant3 = client.collections.get("CollectionWithAutoMTEnabled").with_tenant("tenant3")
tenant3.data.insert({"text": "This a single insert for tenant 3"})
Can you paste a reproducible code?
Not sure I understood what you actually are running.
Thanks!
We just race condition posted here. I’ll move my edit to this reply instead:
Looks like my sandbox, as well as the paid server version that deploys at the moment is now 1.24.6 (you can see above I started out with 1.25+). Whereas, I believe the auto-adding multi-tenant feature is in 1.25+. Perhaps all the errors I’ve been getting have something to do with server versions getting live swapped around on me? Thinking I’ll switch to manual management, and if that works fine, potentially check back in on this feature in a few weeks/months.