Ingesting PDF documents for embedding-based search (often called Semantic Search or Vector Search) in Amazon OpenSearch is a fundamentally different process than standard log or text ingestion.
While standard ingestion involves sending raw text or JSON fields to be indexed by keyword, embedding-based ingestion requires transforming unstructured PDF content into high-dimensional vector embeddings before storing them.
How Embedding-Based Ingestion Differs
Standard Ingestion: You send text directly. OpenSearch uses inverted indexes (like a book's index) to perform keyword matching.
Embedding-Based Ingestion: You must first extract text from the PDF, send that text to an AI model (like Amazon Bedrock or a local model) to generate numerical vectors, and then store those vectors in an OpenSearch
knn(k-nearest neighbors) index.
Steps for Embedding-Based Ingestion in OpenSearch
1. Preprocessing and Text Extraction
PDFs are binary files. OpenSearch cannot read them directly. You must first extract the text:
Use a library (like
PyPDF2,LangChain, or Amazon Textract) to convert the PDF content into clean, readable text strings.Chunking: Since AI models have input limits, you must split long PDF text into smaller, overlapping "chunks" (e.g., 500 tokens each).
2. Vectorization (The Embedding Step)
You transform your text chunks into vectors.
Send your chunks to an embedding model (e.g.,
amazon.titan-embed-text-v1via Amazon Bedrock).The model returns a list of floating-point numbers (e.g., 1024 dimensions) representing the semantic meaning of that chunk.
3. Configuring an OpenSearch knn Index
Before you store the vectors, your index must be configured to support Vector Search.
You create an index with a
knn_vectorfield type.You must define an engine (e.g.,
nmslib,faiss) and a method (e.g.,hnswfor high performance) to allow for efficient similarity searching.
4. Ingestion Pipeline / Integration
You have two primary ways to connect this:
The Ingestion Pipeline (Recommended): You can use an OpenSearch Ingestion Pipeline to automatically call your embedding model (like Bedrock) while the document is being indexed. This keeps the vectorization logic inside the OpenSearch ecosystem.
Application-Side Processing: Your application extracts the text, calls the Bedrock API to get the embedding, and then sends the final JSON document (containing both the raw text and the vector) to the OpenSearch Bulk API.
Summary: Why is it different?
| Feature | Standard Document Ingestion | Embedding-Based Ingestion |
| Data Format | JSON / Raw Logs | JSON + Vector Array |
| Processing | Tokenization (Keyword splitting) | ML Inference (Model generation) |
| Index Type | Inverted Index | KNN Index (knn_vector field) |
| Search Method | BM25 / Keyword Match | Vector Similarity (Cosine/Euclidean) |
Key Architectural Note: The "In-Cluster" Approach
Amazon OpenSearch Service now supports "ML Commons," which allows you to integrate your OpenSearch domain directly with Amazon Bedrock. This is highly efficient because:
You define an Ingestion Pipeline inside OpenSearch.
You send the raw PDF text chunks to that pipeline.
OpenSearch automatically calls Bedrock to generate the embeddings.
OpenSearch indexes the vectors for you, abstracting away much of the manual vector handling in your application code.
No comments:
Post a Comment