DEV Community

César Freitas
César Freitas

Posted on

Prepare PDFs for a vector database the right way

Preparing PDFs for a Vector Database the Right Way

As more data becomes digitized and moved into vector databases, the importance of preparing these documents properly grows. The problem is that not all PDFs are created equal – they can be scanned or photographed, contain handwritten notes, or have varying levels of legibility. This makes it a challenge to extract meaningful information from them without investing significant time in manual preprocessing.

Document Intelligence API to the Rescue

One solution to this issue is Document Intelligence API. By using this API, you can turn any PDF (digital or scanned) into clean, LLM/RAG-ready Markdown with built-in OCR (Optical Character Recognition). This means that you don't have to worry about preprocessing your documents beforehand – the API handles it for you.

The API also extracts specific types of data from invoices and receipts as JSON. This is incredibly useful if you're building an application where you need to parse this information programmatically.

What Does a Typical Request/Response Look Like?

When you make a request to Document Intelligence API, you'll typically provide a PDF file or a URL pointing to it. The response will include the processed Markdown document and any extracted data in JSON format.

The Markdown document is clean and ready for use with Large Language Models (LLMs) or Recurrent Attention Gates (RAGs). It's essentially a formatted text that can be easily parsed by these models, allowing you to build more accurate applications.

On the other hand, the extracted data from invoices and receipts will be in JSON format. This is useful if you want to store this information in a database for later use or pass it on to another application for further processing.

While the technical details of how Document Intelligence API works are complex and not relevant to most developers, understanding what output you can expect from the API is crucial when deciding whether to integrate it into your project.

Getting Started

If you're interested in trying out Document Intelligence API for yourself, we recommend checking out RapidAPI. They offer a free tier that allows you to make a limited number of requests per month without incurring costs. This is an excellent way to test the API and see if it meets your needs before committing to a paid plan.

Keep in mind that using third-party APIs like Document Intelligence can be a significant investment, especially if you're building a large application. However, many developers find that the benefits far outweigh the costs – improved efficiency, increased accuracy, and reduced manual preprocessing time are just a few of the advantages of working with a well-designed API.

By following these guidelines and using Document Intelligence API to prepare your PDFs for vector databases, you can unlock new possibilities for your application and take advantage of the latest developments in document analysis technology.

Quick example

curl -X POST 'https://document-intelligence3.p.rapidapi.com/v1/pdf-to-markdown' \
  -H 'X-RapidAPI-Key: YOUR_RAPIDAPI_KEY' \
  -H 'X-RapidAPI-Host: document-intelligence3.p.rapidapi.com' \
  -H 'Content-Type: application/json' \
  -d '{"url":"https://example.com/file.pdf"}'
Enter fullscreen mode Exit fullscreen mode

Try it: the Document Intelligence API is live on RapidAPI with a free tier — get your key here.

Top comments (0)