OpenAI

Generate PDF and DOCX file embeddings using OpenAI in Python

Extract text from PDF or DOCX files and create embeddings with OpenAI’s API. Set file paths, read and split text into chunks, generate embeddings for each chunk, and store the results.

Required packages

You need below packages to use the code generated by recipe. All packages are automatically installed in MLJAR Studio.

openai>=1.35.14

pypdf>=4.1.0

python-docx>=1.1.2

Interactive recipe

You can use below interactive recipe to generate code. This recipe is available in MLJAR Studio.

In the below recipe, we assume that you have following variables available in your notebook:

  • client (type OpenAI)

Python code

# Python code will be here

Code explanation

  1. Set the file path.
  2. Read the file.
  3. Split text from the file into chunks.
  4. Generate embeddings for each chunk.
« Previous
Embeddings