Rag Pdf Query
rag-pdf-llama-indexnebius-token-factory-cookbookrag
Export
Query PDF documents using RAG (Llama-Index + Nebius AI)
This example shows querying a PDF using llama index framework and running LLM on Nebius Token Factory
References and Acknowledgements
Pre requisites
- Nebius API key. Sign up for free at Token Factory
1 - Setup
1.1 - If running on Google Colab
Add NEBIUS_API_KEY to Secrets as follows

1.2 - If running locally
Create an .env file with NEBIUS_API_KEY as follows
NEBIUS_API_KEY=your_api_key_goes_here
2 - Install Dependencies
[1]
NOT Running in Colab
[2]
3 - Load Configuration
[3]
✅ NEBIUS_API_KEY found
4 - Data
[4]
5 - Setup Embedding Model
We have a choice of local embedding model (fast) or running it on the cloud
If running locally:
- choose smaller models
- less accuracy but faster
If running on the cloud
- We can run large models (billions of params)
[5]
6 - Setup LLama Index with Nebius
We can use llama_index.llms.nebius.NebiusLLM or llama_index.llms.litellm.LiteLLM.
See examples below
[6]
6 - Read PDFs
[7]
[8]
Loaded 1 docs from 1 files
[9]
CPU times: user 11.6 s, sys: 344 ms, total: 12 s Wall time: 9.78 s
7 - Query documents
[10]
Attention mechanism appears to be a concept related to artificial intelligence and machine learning, with various subsections and topics discussed, including scaled dot-product attention, multi-head attention, applications of attention, and self-attention. It seems to be a key component in training and optimizing models, with discussions on positional encoding, embeddings, and softmax. However, the exact definition and explanation of the attention mechanism are not explicitly provided.
[11]
{'31b40151-7d77-440a-91e3-5911a070dff9': {'file_path': '/home/sujee/my-stuff/projects/nebius/token-factory-cookbook-1/rag/rag-pdf-llama-index/data/attention.pdf',
, 'file_name': 'attention.pdf',
, 'file_type': 'application/pdf',
, 'file_size': 2215244,
, 'creation_date': '2025-07-07',
, 'last_modified_date': '2025-07-07'},
, '0409e07f-8930-4a01-806d-b94ce9301994': {'file_path': '/home/sujee/my-stuff/projects/nebius/token-factory-cookbook-1/rag/rag-pdf-llama-index/data/attention.pdf',
, 'file_name': 'attention.pdf',
, 'file_type': 'application/pdf',
, 'file_size': 2215244,
, 'creation_date': '2025-07-07',
, 'last_modified_date': '2025-07-07'}}