VOOZH about

URL: https://www.geeksforgeeks.org/artificial-intelligence/building-ai-application-with-llamaindex/

⇱ Building an AI application with LlamaIndex - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Building an AI application with LlamaIndex

Last Updated : 14 Apr, 2026

LlamaIndex is an open source library that helps build AI applications by integrating agents with various data sources, offering a modular approach for tasks like chatbots, document analysis and NLP. Here we will build a movie recommendation bot using LlamaIndex, where a user query is processed, relevant data is retrieved and recommendations are generated.

  • Query Input: The user enters a query like “Show me some action movies.”
  • Document Retrieval: The retriever searches indexed movie data (VectorStoreIndex) to find relevant results.
  • Response Generation: The model combines the query and retrieved data to generate recommendations.

Step 1: Installing Required Packages

  • llama-index: Used for indexing and querying large datasets.
  • transformers: Provides access to pre-trained models.
  • torch: Deep learning framework for running models.
  • accelerate, bitsandbytes: Optimize performance and memory for large models.

Step 2: Importing Required Libraries

Step 3: Setting Up Models and Embeddings

  • Use a Hugging Face embedding model (all-MiniLM-L6-v2) to convert movie data into vector representations.
  • Set up a language model (TinyLlama-1.1B-Chat-v1.0) for generating responses to user queries.
  • Configure parameters like tokenization, context window and token limits for efficient performance.
👁 model-training-
Training

Step 4 Loading Data from CSV

  • Load the dataset and convert each row into Document objects for indexing.
  • Extract fields like ID, title, genre and rating from each row.
  • Create Document objects using this data for further processing.

You can download dataset from here.

Step 5: Document Creation and Indexing

  • Build a VectorStoreIndex from the movie documents to enable efficient search and retrieval.
  • Create a query engine to interact with the index and handle user queries.

Step 6: Querying and Displaying Recommendations

  • The user provides a movie genre as input through the loop.
  • A structured prompt is created to guide the model to return movie titles with ratings in a specific format.
  • The query is passed to the query engine, which retrieves relevant documents and generates recommendations.
  • The response is printed directly using response.response, ensuring clean and readable output.

Output:

👁 output
Output

You can download source code from here.

Applications

  • LlamaIndex can recommend products, movies or content by matching user preferences with indexed data.
  • Helps build search systems for large datasets like company documents or FAQs using natural language queries.
  • Enables chatbots and virtual assistants to understand user queries and provide intelligent responses using indexed knowledge.
  • Can be used to analyze reviews or social media data to understand public sentiment about products or services.
  • Supports retrieval across multiple languages, making it useful for global applications.
Comment
Article Tags:

Explore