# Async BATCH request for real-time ANN search

**URL:** <https://forum.weaviate.io/t/async-batch-request-for-real-time-ann-search/1417>\
**Category:** General\
**Tags:** developer-experience, python\
**Created:** [February 7, 2024, 2:01pm UTC](https://forum.weaviate.io/t/async-batch-request-for-real-time-ann-search/1417 "2024-02-07T14:01:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![justatom](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@justatom](https://forum.weaviate.io/u/justatom)\
**Post date:** [February 7, 2024, 2:01pm UTC](https://forum.weaviate.io/t/async-batch-request-for-real-time-ann-search/1417/1 "2024-02-07T14:01:47Z")

</div>

Hi everyone!

I am running weaviate instance locally and referring to this stackoverflow [post](https://stackoverflow.com/questions/71558676/does-weaviate-support-bulk-query/71561939#71561939).

So, let’s say that all the logic with respect to weaviate API incapsulated into `IWeaviateDocStore` class. I’m receiving requests in async manner from the client and I’d like to perform ANN search on them using batches instead of manual one by one iteration. Is that possible now with weavaite? The pseudo-code is below:

```auto

import json
import aiohttp
import asyncio
from sir.storing.weaviate import IWeaviateDocStore

async def search(query_string: str, url:str):   

    query = '''
        {
            Get{
                Article(
                    limit: 20
                    hybrid: {
                        query: "<QUERY_PLACEHOLDER>"
                        alpha: 0.75
                        fusionType: relativeScoreFusion
                    }){
                        texte
                        title
                    }
                    _additional {
                        score
                    }
                }
            }
        }
    '''.replace("<QUERY_PLACEHOLDER>", query_string)

    async with aiohttp.ClientSession() as session:
        async with session.post(url, headers=headers, data=json.dumps({'query': query})) as response:
            return await response.json()

def main():
   BATCH_SIZE = 10
   INCOMING_REQS: List[str] = ["What are the rules of the hunger games by S.Collins?", "What is lumos maxima?", ... ,]
   # HELP. Do I need to manually perform `batching` or I can simply send it to weavaite and it'll handle it automatically?

   session = aiohttp.ClientSession()
   URL = "http://localhost:8080"
   
   batch_reqs = await asyncio.gather(*[search(session=session, url=URL, query_string=query) for query in INCOMING_REQS]
   #
   await session.close()

      
   

if __name__ == " __main__":
   asyncio.run(main())

```

ps. Thx in advance and really sorry if this functionality is already in the docs, haven’t found it.

- [Add Async Client to be able to make asynchronous requests · Issue #88 · weaviate/weaviate-python-client · GitHub](https://github.com/weaviate/weaviate-python-client/issues/88)

---

<div class="post-metadata">

**Author:** ![DudaNogueira](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/dudanogueira/32/7846_2.png) [@DudaNogueira](https://forum.weaviate.io/u/DudaNogueira)\
**Post date:** [February 7, 2024, 9:17pm UTC](https://forum.weaviate.io/t/async-batch-request-for-real-time-ann-search/1417/2 "2024-02-07T21:17:15Z")

</div>

Hi!

if you consume the endpoints directly, I believe this would work 🤔

There are some work in progress for allowing this from the client, specially with the new GRPC connection that improves performance.
