Skip to content

Commit 90761a9

Browse files
authored
Image Metadata Test + Sync Implementation (#17844)
* include some metadata when returning image node from llamacloud retriever * version bump * add tests + sync implementation
1 parent 125a06a commit 90761a9

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

llama-index-integrations/indices/llama-index-indices-managed-llama-cloud/llama_index/indices/managed/llama_cloud/api_utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,13 @@ def image_nodes_to_node_with_score(
171171
project_id=project_id,
172172
)
173173
image_base64 = base64.b64encode(image_bytes).decode("utf-8")
174+
image_node_metadata: Dict[str, Any] = {
175+
"file_id": raw_image_node.node.file_id,
176+
"page_index": raw_image_node.node.page_index,
177+
}
174178
image_node_with_score = NodeWithScore(
175-
node=ImageNode(image=image_base64), score=raw_image_node.score
179+
node=ImageNode(image=image_base64, metadata=image_node_metadata),
180+
score=raw_image_node.score,
176181
)
177182
image_nodes.append(image_node_with_score)
178183
return image_nodes

llama-index-integrations/indices/llama-index-indices-managed-llama-cloud/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ exclude = ["**/BUILD"]
3434
license = "MIT"
3535
name = "llama-index-indices-managed-llama-cloud"
3636
readme = "README.md"
37-
version = "0.6.6"
37+
version = "0.6.7"
3838

3939
[tool.poetry.dependencies]
4040
python = ">=3.9,<4.0"
17.8 KB
Binary file not shown.

llama-index-integrations/indices/llama-index-indices-managed-llama-cloud/tests/test_indices_managed_llama_cloud.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
PipelineFileCreate,
66
ProjectCreate,
77
CompositeRetrievalMode,
8+
LlamaParseParameters,
89
)
910
from llama_index.indices.managed.llama_cloud import (
1011
LlamaCloudIndex,
1112
LlamaCloudCompositeRetriever,
1213
)
1314
from llama_index.embeddings.openai import OpenAIEmbedding
14-
from llama_index.core.schema import Document
15+
from llama_index.core.schema import Document, ImageNode
1516
import os
1617
import pytest
1718
from uuid import uuid4
@@ -35,6 +36,7 @@ def remote_file() -> Tuple[str, str]:
3536

3637
def _setup_empty_index(
3738
client: LlamaCloud,
39+
multi_modal_index: bool = False,
3840
) -> LlamaCloudIndex:
3941
# create project if it doesn't exist
4042
project_create = ProjectCreate(name=project_name)
@@ -47,6 +49,7 @@ def _setup_empty_index(
4749
name="test_empty_index_" + str(uuid4()),
4850
embedding_config={"type": "OPENAI_EMBEDDING", "component": OpenAIEmbedding()},
4951
transform_config=AutoTransformConfig(),
52+
llama_parse_parameters=LlamaParseParameters(take_screenshot=multi_modal_index),
5053
)
5154
return client.pipelines.upsert_pipeline(
5255
project_id=project.id, request=pipeline_create
@@ -279,6 +282,36 @@ def test_index_from_documents():
279282
assert "3" not in docs
280283

281284

285+
@pytest.mark.skipif(
286+
not base_url or not api_key, reason="No platform base url or api key set"
287+
)
288+
@pytest.mark.skipif(not openai_api_key, reason="No openai api key set")
289+
@pytest.mark.integration()
290+
def test_image_retrieval() -> None:
291+
pipeline = _setup_empty_index(
292+
LlamaCloud(token=api_key, base_url=base_url), multi_modal_index=True
293+
)
294+
295+
index = LlamaCloudIndex(
296+
name=pipeline.name,
297+
project_name=project_name,
298+
api_key=api_key,
299+
base_url=base_url,
300+
)
301+
302+
file_path = "llama-index-integrations/indices/llama-index-indices-managed-llama-cloud/tests/data/Simple PDF Slides.pdf"
303+
file_id = index.upload_file(file_path, wait_for_ingestion=True)
304+
305+
retriever = index.as_retriever(retrieve_image_nodes=True)
306+
nodes = retriever.retrieve("1")
307+
assert len(nodes) > 0
308+
309+
image_nodes = [n.node for n in nodes if isinstance(n.node, ImageNode)]
310+
assert len(image_nodes) > 0
311+
assert all(n.metadata["file_id"] == file_id for n in image_nodes)
312+
assert all(n.metadata["page_index"] >= 0 for n in image_nodes)
313+
314+
282315
@pytest.mark.skipif(
283316
not base_url or not api_key, reason="No platform base url or api key set"
284317
)

0 commit comments

Comments
 (0)