Integrate LlamaIndex with Alibaba Cloud AISearch
Parse documents and images from local or remote files via Alibaba Cloud AI Search into LlamaIndex.
Why it matters
Connect LlamaIndex to Alibaba Cloud's AISearch service to ingest and process various document and image types for advanced retrieval and analysis.
Outcomes
What it gets done
Read local and remote documents (PDF, DOCX, PPTX) using AISearch.
Process images (JPG, PNG) for OCR and analysis via AISearch.
Configure AISearch endpoint and API keys for integration.
Enable RAG indexing for diverse file formats.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/li-reader-readers-alibabacloud-aisearch | bash Overview
LlamaIndex Readers Integration: Alibabacloud_Aisearch
Two LlamaIndex readers that parse documents and images via Alibaba Cloud AI Search, from local files or remote URLs. Use the document reader for ppt/doc/pdf files and the image reader for images, local or remote, given a provisioned API key.
What it does
The Alibabacloud AISearch Readers Integration parses documents and images using Alibaba Cloud's AI Search service, loading the results into LlamaIndex. Two reader classes cover the two content types: AlibabaCloudAISearchDocumentReader handles document formats (ppt/pptx, doc/docx, pdf), and AlibabaCloudAISearchImageReader handles images. Both are configured with an endpoint and an aisearch_api_key, either passed to the constructor or set via the AISEARCH_ENDPOINT and AISEARCH_API_KEY environment variables.
For local files, both readers can be wired into SimpleDirectoryReader via a file_extractor mapping - document extensions (.pdf, .docx, .doc, .ppt, .pptx) routed to the document reader, and image extensions (.jpg, .jpeg, .png, .bmp, .tiff) routed to the image reader - so a single directory scan dispatches each file to the right parser. For remote files, AlibabaCloudAISearchImageReader can also be initialized with a specific service_id (for example an OCR-focused analysis service) and called directly with a list of image URLs; the file type is inferred from the URL's extension automatically, or can be specified manually when it can't be inferred.
When to use - and when NOT to
Use the document reader for local ppt/pptx, doc/docx, or PDF files, and the image reader for local or remote images - choosing a specific service_id for the image reader when you need a particular analysis mode like OCR. Use the SimpleDirectoryReader file_extractor pattern when parsing a mixed directory of documents and images in one pass. Do not use it without an Alibaba Cloud AI Search endpoint and API key already provisioned; both readers require valid credentials to function.
Capabilities
AlibabaCloudAISearchDocumentReader parses ppt/pptx, doc/docx, and PDF files. AlibabaCloudAISearchImageReader parses images from local files or remote URLs, with optional service_id selection for a specific analysis mode.
How to install
pip install llama-index-readers-alibabacloud-aisearch
Requires an Alibaba Cloud AI Search endpoint and aisearch_api_key, passed directly or via environment variables.
Who it's for
Developers who need documents or images parsed via Alibaba Cloud's AI Search service and loaded into LlamaIndex, whether from local files or remote URLs.
Source README
LlamaIndex Readers Integration: Alibabacloud_Aisearch
Installation
pip install llama-index-readers-alibabacloud-aisearch
Usage
Supported file types: ppt/pptx, doc/docx, pdf, images and so on.
For further details, please visit:
You can specify the endpoint and aisearch_api_key in the constructor, or set the environment variables AISEARCH_ENDPOINT and AISEARCH_API_KEY.
Read local files
from llama_index.readers.alibabacloud_aisearch import (
AlibabaCloudAISearchDocumentReader,
AlibabaCloudAISearchImageReader,
)
from llama_index.core import SimpleDirectoryReader
document_reader = AlibabaCloudAISearchDocumentReader()
image_reader = AlibabaCloudAISearchImageReader()
file_extractor = {}
for suffix in (".pdf", ".docx", ".doc", ".ppt", ".pptx"):
file_extractor[suffix] = document_reader
for suffix in (".jpg", ".jpeg", ".png", ".bmp", ".tiff"):
file_extractor[suffix] = image_reader
documents = SimpleDirectoryReader(
"./data", file_extractor=file_extractor
).load_data(show_progress=True)
print(documents)
Read remote files
from llama_index.readers.alibabacloud_aisearch import (
AlibabaCloudAISearchImageReader,
)
image_reader = AlibabaCloudAISearchImageReader(
service_id="ops-image-analyze-ocr-001"
)
image_urls = [
"https://img.alicdn.com/imgextra/i1/O1CN01WksnF41hlhBFsXDNB_!!6000000004318-0-tps-1000-1400.jpg",
]
### The file_type is automatically determined based on the file extension.
### If it cannot be identified, manual specification of the file_type is required.
documents = image_reader.load_data(file_path=image_urls, file_type="jpg")
print(documents)
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.