LangExtract
Set up LangExtract with Ollama and expose it as a local API for PDI.
Architecture
PDI → HTTP Client → LangExtract API → Ollama model → JSON response
Prerequisites
Pentaho Data Integration
9.x
Community or EE. Spoon and Pan available.
Python
3.10+
Requires pip and venv.
LangExtract
Current GitHub source
Installed from google/langextract.
FastAPI
Current
REST wrapper for LangExtract.
Uvicorn
Current
ASGI server for the API.
Ollama
0.3+
Local LLM runtime.
Ollama Python package
Current
Required by the sample service code.
Model
llama3.1:8b
Pulled locally with Ollama.
PostgreSQL
Optional
Use only if you plan to persist extracted records.
Create project directory
Windows (PowerShell)
Unix
Create and activate virtual environment
Windows
Unix
Install dependencies
Identical on both platforms:
Save the script
Save server.py into the project directory:
Windows:
C:\langextract_api\server.pyUnix:
/opt/langextract_api/server.py
Save this file as server.py:
Pull the Ollama model
Identical on both platforms:
Start Ollama
Identical on both platforms:
Leave this running in a separate terminal, or configure it as a service (see step 8).
Start the LangExtract service
Windows
Unix
Run as a background service
Windows - NSSM
Unix - systemd
Create /etc/systemd/system/langextract.service:
Then enable and start:
bash
Open firewall
Windows
Unix (ufw)
Unix (firewalld / RHEL)
Verify
Identical on both platforms:
Response:
Swagger UI (browser): http://localhost:8765/docs
Verify with a test request
Windows
Run a test extraction:
Response:
Unix
Run a test extraction:
Response:
Success means the API returns an extractions array with extracted values and character offsets.
Call the API from PDI
Use the HTTP Client step:
URL:
http://localhost:8765/extractMethod:
POSTContent-Type:
application/jsonRequest body field: your JSON payload
Response field:
response_json
Then parse the response with JSON Input:
Source is from a field:
response_jsonPath:
$.extractions[*]Fields:
class,text,start,end
PostgreSQL
Troubleshooting
Last updated
Was this helpful?
