Grounding Images from the Documents
Hi
I was following the following code from Agentic Document Extraction training at Deeplearning.ai:
In my document, i was able to see the whole page (the correct page) as per my prompt. But Im not seeing the cropped bounding box where the answer is generated from. What could be the problem?
I was assuming that it will show me the cropped area from my document from where the answer is extracted. But it shows the whole pdf page. When i see the parser output, i can see that there is a specific bounding box around the text.
Any support is highly appreciated.
print(f"Inserting new chunks into Chroma...")
added_count = 0
for i, chunk in enumerate(loaded_chunks):
chunk_id = chunk["chunk_id"]
# Add chunk if it does not exist-original
if chunk_id not in existing_ids:
text = chunk.get("text", "")
# Skip empty chunks
if not text or not text.strip():
continue
# Generate Embeddings for chunk text with OpenAI
emb = openai.embeddings.create(
input=text,
model=EMBEDDING_MODEL
).data[0].embedding
# Flatten Metadata (Simple Types Only)
metadata = {
"chunk_type": chunk.get("chunk_type", "unknown"),
"page": chunk.get("page", 0)
}
# Add bbox coordinates to metadata
bbox = chunk.get("bbox")
if bbox and len(bbox) == 4:
metadata["bbox_x0"] = float(bbox[0])
metadata["bbox_y0"] = float(bbox[1])
metadata["bbox_x1"] = float(bbox[2])
metadata["bbox_y1"] = float(bbox[3])
# Store in Chroma
collection.add(
documents=[text],
ids=[chunk_id],
metadatas=[metadata],
embeddings=[emb]
)
added_count += 1
# Progress indicator
if (added_count) % 20 == 0:
print(f" Processed {added_count} new chunks...")
print(f"\n✓ Added {added_count} new chunks, skipped existing chunks")
print(f"Inserting new chunks into Chroma...")
added_count = 0
for i, chunk in enumerate(loaded_chunks):
chunk_id = chunk["chunk_id"]
# Add chunk if it does not exist-original
if chunk_id not in existing_ids:
text = chunk.get("text", "")
# Skip empty chunks
if not text or not text.strip():
continue
# Generate Embeddings for chunk text with OpenAI
emb = openai.embeddings.create(
input=text,
model=EMBEDDING_MODEL
).data[0].embedding
# Flatten Metadata (Simple Types Only)
metadata = {
"chunk_type": chunk.get("chunk_type", "unknown"),
"page": chunk.get("page", 0)
}
# Add bbox coordinates to metadata
bbox = chunk.get("bbox")
if bbox and len(bbox) == 4:
metadata["bbox_x0"] = float(bbox[0])
metadata["bbox_y0"] = float(bbox[1])
metadata["bbox_x1"] = float(bbox[2])
metadata["bbox_y1"] = float(bbox[3])
# Store in Chroma
collection.add(
documents=[text],
ids=[chunk_id],
metadatas=[metadata],
embeddings=[emb]
)
added_count += 1
# Progress indicator
if (added_count) % 20 == 0:
print(f" Processed {added_count} new chunks...")
print(f"\n✓ Added {added_count} new chunks, skipped existing chunks")