2727print (f"📐 Using ColPali model { COLPALI_MODEL_NAME } " )
2828
2929
30- # Create ColPali embedding function using the class-based pattern
31- colpali_embed = cocoindex .functions .ColPaliEmbedImage (model = COLPALI_MODEL_NAME )
32-
33-
3430@cocoindex .transform_flow ()
3531def text_to_colpali_embedding (
3632 text : cocoindex .DataSlice [str ],
@@ -56,38 +52,15 @@ def image_object_embedding_flow(
5652 )
5753 img_embeddings = data_scope .add_collector ()
5854 with data_scope ["images" ].row () as img :
59- ollama_model_name = os .getenv ("OLLAMA_MODEL" )
60- if ollama_model_name is not None :
61- # If an Ollama model is specified, generate an image caption
62- img ["caption" ] = flow_builder .transform (
63- cocoindex .functions .ExtractByLlm (
64- llm_spec = cocoindex .llm .LlmSpec (
65- api_type = cocoindex .LlmApiType .OLLAMA , model = ollama_model_name
66- ),
67- instruction = (
68- "Describe the image in one detailed sentence. "
69- "Name all visible animal species, objects, and the main scene. "
70- "Be specific about type, color, and notable features. "
71- "Mention what each animal is doing."
72- ),
73- output_type = str ,
74- ),
75- image = img ["content" ],
76- )
77- img ["embedding" ] = img ["content" ].transform (colpali_embed )
55+ img ["embedding" ] = img ["content" ].transform (
56+ cocoindex .functions .ColPaliEmbedImage (model = COLPALI_MODEL_NAME )
57+ )
7858
7959 collect_fields = {
8060 "id" : cocoindex .GeneratedField .UUID ,
8161 "filename" : img ["filename" ],
8262 "embedding" : img ["embedding" ],
8363 }
84-
85- if ollama_model_name is not None :
86- print (f"Using Ollama model '{ ollama_model_name } ' for captioning." )
87- collect_fields ["caption" ] = img ["caption" ]
88- else :
89- print (f"No Ollama model '{ ollama_model_name } ' found — skipping captioning." )
90-
9164 img_embeddings .collect (** collect_fields )
9265
9366 img_embeddings .export (
0 commit comments