27
27
print (f"📐 Using ColPali model { COLPALI_MODEL_NAME } " )
28
28
29
29
30
- # Create ColPali embedding function using the class-based pattern
31
- colpali_embed = cocoindex .functions .ColPaliEmbedImage (model = COLPALI_MODEL_NAME )
32
-
33
-
34
30
@cocoindex .transform_flow ()
35
31
def text_to_colpali_embedding (
36
32
text : cocoindex .DataSlice [str ],
@@ -56,38 +52,15 @@ def image_object_embedding_flow(
56
52
)
57
53
img_embeddings = data_scope .add_collector ()
58
54
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
+ )
78
58
79
59
collect_fields = {
80
60
"id" : cocoindex .GeneratedField .UUID ,
81
61
"filename" : img ["filename" ],
82
62
"embedding" : img ["embedding" ],
83
63
}
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
-
91
64
img_embeddings .collect (** collect_fields )
92
65
93
66
img_embeddings .export (
0 commit comments