Deploying Weaviate Python Client to Lambda

I’m deploying a simple test function to a python 3.11 lambda function. I have a weaviate layer attached to it with weaviate-client installed. when i try and import weaviate, I get:

“errorMessage”: “/lib64/libc.so.6: version `GLIBC_2.28’ not found (required by /opt/python/cryptography/hazmat/bindings/_rust.abi3.so)”

it is my understanding that lambda uses an older version of GLIBC. Usually the solution to something like this would be to use an older wheel,

for example: pip install weaviate-client --platform manylinux_2_12_x86_64 --only-binary=:all:

but this leads to conflicting dependancies and wont install. any ideas?

hi @Jonathan_Yapp ! Welcome to our community :hugs:

I have not used weaviate-client with Lambda. :frowning:

I will try to experiment on that this week and will get back here. Also, I can try escalating this with our team.

Thanks!

2 Likes

Were you able to resolve this as well? We added a Lambda Layer with weviate and couldn’t make it to work either.

No i wasn’t able to resolve this and used the REST API instead of the client. You can easily replicate the issue in a docker container that has the older GLIBC.

HI!!

Hey @niknokseyer! Welcome to our community.

@Jonathan_Yapp Good news! I found a fix for this (or I was able to run in lambda)

Sorry for the delay, I was out the past days :slight_smile:

I was able to make it work.

here was how with some example code.

First, create the package and install the dependency

mkdir -p my-lambda-function/package
cd my-lambda-function/package
pip install weaviate-client --platform manylinux2014_x86_64 -t . --only-binary=:all:
cd ..

now we have in our root folder a package folder with all dependencies so far.

I created a lambda_function.py file on this root folder with the contents:

import json
import os
import requests

import weaviate
from weaviate import classes as wvc

CLUSTER_URL = os.environ.get(
    "CLUSTER_URL",
    "https://duda-test-sdfsdfsdf.weaviate.network"
)

CLUSTER_APIKEY = os.environ.get(
    "CLUSTER_APIKEY",
    "PasdasdpUrmLsdfsdfsdfsdfsdfokj"
)

OPENAPI_KEY = os.environ.get(
    "OPENAI_APIKEY",
    "sk-j0sdfsdfsdfsdfdasdasdaO5MsdfsdfsdfYoGVw"
)

def lambda_handler(event, context):
    # if not ?query=some_query, defaults to biology
    query = event.get("queryStringParameters", {}).get("query", "biology")

    client = weaviate.connect_to_wcs(
        cluster_url=CLUSTER_URL,
        auth_credentials=weaviate.auth.AuthApiKey(CLUSTER_APIKEY),
        headers={
                "X-OpenAI-Api-Key": OPENAPI_KEY  # Replace with your inference API key
            }        
    )
    if not client.collections.exists("Question"):
        # create content and import some data
        questions = client.collections.create(
            name="Question",
            vectorizer_config=wvc.config.Configure.Vectorizer.text2vec_openai(),  # If set to "none" you must always provide vectors yourself. Could be any other "text2vec-*" also.
            generative_config=wvc.config.Configure.Generative.openai()  # Ensure the `generative-openai` module is used for generative queries
        )
        # add some data
        resp = requests.get('https://raw.githubusercontent.com/weaviate-tutorials/quickstart/main/data/jeopardy_tiny.json')
        data = json.loads(resp.text)  # Load data

        question_objs = list()
        for i, d in enumerate(data):
            question_objs.append({
                "answer": d["Answer"],
                "question": d["Question"],
                "category": d["Category"],
            })
        questions.data.insert_many(question_objs)
    questions = client.collections.get("Question")
    # return results
    response = {}
    # single prompt
    results = questions.generate.near_text(
        query=query,
        limit=1,
        single_prompt="Explain {answer} as you might to a five-year-old."
    )
    response["single_prompt"] = results.objects[0].generated
    # group task
    results = questions.generate.near_text(
        query=query,
        limit=2,
        grouped_task="Write a tweet with emojis about these facts."
    )
    response["grouped_task"] = results.generated
    client.close()
    return {
        'statusCode': 200,
        'body': json.dumps(response)
    }

now you need to zip those files on this specific order/way:

cd package
zip -r ../deployment.zip .
cd ..
zip deployment.zip lambda_function.py

Let me know if this works on your side, as this could be a starter pack recipe for weaviate client in lambda :slight_smile:

Thanks!

Thank you, I will try that out (post vacation!) and report back.

1 Like