Structured on-premise extraction with LLM and Ollama

Learn to extract structured data from Markdown and PDF documents using Ollama and CocoIndex with just ~100 lines of Python code. Run LLM models locally and create efficient data indexes.

viernes, 21 de marzo de 2025 • 2 min read • Q2BSTUDIO Team

Company-Software-Apps

In this blog, we will show you how to use Ollama to extract structured data locally and deploy it on your own cloud or server.

We will use Python documentation in PDF format as an example. With just about 100 lines of Python code, you can perform this process efficiently.

Ollama makes it easy to run large language models (LLMs) on your computer. To get started, download and install Ollama, then run the following command to get your favorite LLM model:

ollama pull llama3.2

We define the structure of the data to be extracted from the Python document, organizing it into classes that contain information about modules, classes, methods, and arguments.

Then, we set up the extraction flow using CocoIndex to process documents in Markdown format. The LLM extraction function takes the document content as input and returns structured data in a defined format.

Once the information is extracted, we can store it in a PostgreSQL database for later querying and analysis.

To test the extraction, simply run these commands:

python main.py cocoindex setup
python main.py cocoindex update

After completing this process, you will be able to query the information stored in the database and analyze it through SQL queries.

At Q2BStudio, a company specialized in development and technology services, we help organizations implement advanced data processing and automation solutions using artificial intelligence. If you are looking to optimize your information management and harness the power of artificial intelligence in your company, contact us.

We also explore how to convert PDF files into Markdown to extract structured data, using custom functions within CocoIndex. This makes it easy to integrate text extraction from different formats into an automated data flow.

At Q2BStudio, we work with technologies that facilitate data management and transformation, providing innovative solutions to companies in different sectors. If you need assistance implementing advanced data extraction and analysis processes, our team is ready to help you.

A BREAK?

Play for a moment before you go

OUR SERVICES

How we can help you

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.