9999
100100 <figure style =" text-align : center ;" >
101101 <img
102- src="/assets/RAG Flow.webp"
102+ src="/assets/RAG- Flow.webp"
103103 alt="High-Level RAG Flow Diagram: User Query -> RAG System -> Grounded Answer"
104104 style="max-width: 80%; height: auto; margin: 1em auto; display: block;"
105105 />
@@ -119,7 +119,7 @@ cover:
119119
120120 <figure style =" text-align : center ;" >
121121 <img
122- src="/assets/Indexing Flow.webp"
122+ src="/assets/Indexing- Flow.webp"
123123 alt="Indexing Flow Diagram: Documents -> Gemini Embedding -> Vector Embeddings -> ChromaDB Vector Store"
124124 style="max-width: 80%; height: auto; margin: 1em auto; display: block;"
125125 />
@@ -194,23 +194,23 @@ cover:
194194 We need to tell ChromaDB how to generate embeddings using the Gemini API.
195195 </p >
196196
197- ``` python # --- 4. Define Gemini Embedding Function for ChromaDB --- from
198- chromadb import Documents, EmbeddingFunction, Embeddings from google.api_core
199- import retry from google import genai from google.genai import types
200- is_retriable = lambda e : (isinstance (e, genai.errors.APIError) and e.code in
201- {429 , 503 }) class GeminiEmbeddingFunction (EmbeddingFunction ): document_mode =
202- True # Toggle between indexing docs and embedding queries
203- @retry.Retry (predicate = is_retriable) def __call__(self, input_texts:
204- Documents) -> Embeddings: task = " retrieval_document" if self .document_mode
205- else " retrieval_query" print (f " Embedding { ' documents' if self .document_mode
206- else ' query' } ({len (input_texts)})... " ) try: # Assuming 'client' is
207- initialized Google GenAI client response = client.models.embed_content(
208- model = " models/text-embedding-004" , contents = input_texts,
209- config = types.EmbedContentConfig(task_type = task), # Specify task type ) return
210- [e.values for e in response.embeddings] except Exception as e: print (f " Error
211- during embedding: { e} " ) return [[] for _ in input_texts]
197+ ``` python # --- 4. Define Gemini Embedding Function for ChromaDB --- from
198+ chromadb import Documents, EmbeddingFunction, Embeddings from google.api_core
199+ import retry from google import genai from google.genai import types
200+ is_retriable = lambda e : (isinstance (e, genai.errors.APIError) and e.code in
201+ {429 , 503 }) class GeminiEmbeddingFunction (EmbeddingFunction ): document_mode =
202+ True # Toggle between indexing docs and embedding queries
203+ @retry.Retry (predicate = is_retriable) def __call__(self, input_texts:
204+ Documents) -> Embeddings: task = " retrieval_document" if self .document_mode
205+ else " retrieval_query" print (f " Embedding { ' documents' if self .document_mode
206+ else ' query' } ({len (input_texts)})... " ) try: # Assuming 'client' is
207+ initialized Google GenAI client response = client.models.embed_content(
208+ model = " models/text-embedding-004" , contents = input_texts,
209+ config = types.EmbedContentConfig(task_type = task), # Specify task type ) return
210+ [e.values for e in response.embeddings] except Exception as e: print (f " Error
211+ during embedding: { e} " ) return [[] for _ in input_texts]
212212< / div>
213- ````
213+ ```
214214
215215< p>< strong> 2 . < span style = " color:#8ac7db" > Setting up ChromaDB and Indexing:< / span>< / strong>< br>
216216We create a ChromaDB collection and add our documents. < code> get_or_create_collection< / code> makes this idempotent.< / p>
@@ -408,4 +408,4 @@ I hope this walkthrough provides a clear picture of how this smarter FAQ bot wor
408408
409409< / div>
410410
411- < / div>
411+ < / div>
0 commit comments