Menu

How to create gemini-embedding-2 using Google Batch API
📰
0

How to create gemini-embedding-2 using Google Batch API

DEV Community·Alin Climente·about 1 month ago
#aROTFy9c
#gemini#googlecloud#python#tutorial#name#file
Reading 0:00
15s threshold

Here are some sample functions extracted directly from an app I'm building. Wasted some hours on it to get it working so if any dev or LLM comes on to this article - here is how to do it right first time. First we need to create the .jsonl file for the google embeddings batch api. Most important part to retain here is the format from payload . def create_jsonl_for_embeddings ( self ): ta = TypeAdapter ( list [ VAnchorText ]) jsonl_path = SURSE_LEGISLATIE_JUST_EXPANDED_DIR / " embeddings-requests.jsonl " with open ( jsonl_path , " w " , encoding = " utf-8 " ) as f : for s in surse_legislatie_just : toc_path = ( SURSE_LEGISLATIE_JUST_EXPANDED_DIR / s . slug / f " toc- { s . slug } .json " ) if not toc_path . exists (): continue toc_data = SurseConsolidate . model_validate_json ( toc_path . read_text ()) for c in toc_data . consolidari : anchors_path = ( SURSE_LEGISLATIE_JUST_EXPANDED_DIR / s . slug / c . html_name . replace ( " .html " , " .json " ) ) if not anchors_path .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More