weaviate-python-client icon indicating copy to clipboard operation
weaviate-python-client copied to clipboard

Introduce `WeaviateAsyncClient` as async alternative to `WeaviateClient`

Open tsmith023 opened this issue 10 months ago • 1 comments

  • Changes base implementation to be purely async using httpx and grpclib(instead of google's grpc due to issues)
  • Uses base implementation in WeaviateAsyncClient directly
  • Subdivides the codebase into **/asy/*.py and **/sy/*.py directories within each namespace directory
  • Replace WeaviateClient internal calls with event-loop-wrapped blocking calls using the base async implementation
  • WeaviateClient spins up its own personal event loop thread that it schedules async calls to. Should this be a global singleton instead?
  • client.batch is only available on the WeaviateClient object, since it is a purely sync algorithm. It depends on the new higher-level event loop thread

tsmith023 avatar Apr 12 '24 17:04 tsmith023

Great to see you again! Thanks for the contribution.

beep boop - the Weaviate bot 👋🤖

PS:
Are you already a member of the Weaviate Slack channel?

weaviate-git-bot avatar Apr 13 '24 02:04 weaviate-git-bot

I'm following this as well. I'm looking forward to the async client :)

rolandgvc avatar May 10 '24 12:05 rolandgvc

Codecov Report

Attention: Patch coverage is 93.09133% with 118 lines in your changes missing coverage. Please review.

Please upload report for BASE (dev/1.26@4602a26). Learn more about missing BASE report.

Files Patch % Lines
integration/conftest.py 81.72% 17 Missing :warning:
weaviate/connect/v4.py 86.00% 14 Missing :warning:
weaviate/collections/collection/async_.py 77.77% 12 Missing :warning:
weaviate/event_loop.py 80.70% 11 Missing :warning:
integration/test_batch_v4.py 85.71% 8 Missing :warning:
integration/test_collection_async.py 91.25% 7 Missing :warning:
weaviate/client_base.py 92.30% 6 Missing :warning:
weaviate/collections/collection/sync.py 82.14% 5 Missing :warning:
weaviate/collections/collections/async_.py 91.83% 4 Missing :warning:
weaviate/connect/authentication_async.py 95.40% 4 Missing :warning:
... and 19 more
Additional details and impacted files
@@             Coverage Diff             @@
##             dev/1.26    #1007   +/-   ##
===========================================
  Coverage            ?   94.27%           
===========================================
  Files               ?      213           
  Lines               ?    20490           
  Branches            ?        0           
===========================================
  Hits                ?    19317           
  Misses              ?     1173           
  Partials            ?        0           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar May 31 '24 23:05 codecov-commenter

@rolandgvc, we have released v4.7.0b0 here as an initial pre-release of the new async implementation!

We're aiming to have a week or two of community engagement on the beta to get feedback and find bugs. If you're happy to test it out it would be great to hear your feedback too 😁

tsmith023 avatar Jun 10 '24 17:06 tsmith023

Here's some example usage to see how it works!

import weaviate
import weaviate.classes as wvc

async def async_example() -> None:
    async with weaviate.use_async_with_local() as client:
        collection = await client.collections.create(
            properties=[
                wvc.config.Property(name="name", data_type=DataType.TEXT),
            ],
            vectorizer_config=wvc.config.Configure.Vectorizer.none(),
        )
        await collection.data.insert_many(
            [
                {"name": "John Doe"},
            ]
        )
        res = await collection.query.fetch_objects()
        assert len(res.objects) == 1
        assert res.objects[0].properties["name"] == "John Doe"

tsmith023 avatar Jun 11 '24 10:06 tsmith023

Hi great work y'all we really needed this 👏 Is there some documentation about this? From what I gather in test cases, we can use use_async flag on client instantiation and sync functions become async?

gokturkDev avatar Jun 20 '24 06:06 gokturkDev

One more, is this ready for production code yet or should we wait for the full release?

gokturkDev avatar Jun 20 '24 06:06 gokturkDev

One more, is this ready for production code yet or should we wait for the full release?

please wait for the full release for production - but please try it out now so we can release it as quickly as possible :)

Is there some documentation about this? From what I gather in test cases, we can use use_async flag on client instantiation and sync functions become async?

Not yet - basically you instantiate the async client and then all functions are async

dirkkul avatar Jun 20 '24 07:06 dirkkul

Great looking forward to the release 👍 This might be too big of a hussle now but I would suggest embedding the async functions into WeaviateClient rather than creating a separate AsyncClient class, as a lot of projects (and ours) use a wrapper class for interacting with weaviate, therefore a singleton client is used. Now a separate async client is needed to be instantiated, which is a bit inconvenient

gokturkDev avatar Jun 20 '24 11:06 gokturkDev

This might be too big of a hussle now but I would suggest embedding the async functions into WeaviateClient rather than creating a separate AsyncClient class, as a lot of projects (and ours) use a wrapper class for interacting with weaviate, therefore a separate async wrapper class is needed instead of just adding new async methods, which is a bit inconvenient

The sync class is now basically a wrapper around the async functions - the clients itself are duplicated for typing reasons, but almost everything else is async under the hood and called from the sync client

dirkkul avatar Jun 20 '24 11:06 dirkkul

Hi when is this going to be in the release version

gokturkDev avatar Jul 18 '24 18:07 gokturkDev