Steps to Install and Use LlamaIndex
- Get LlamaIndex on Your Computer
- Ask a grown-up to open their computer’s “command box” (it’s like a magic typing spot).
- Type this and press Enter:
pip install llama-index
- Wait a little bit—it’s like downloading a new toy for your robot friend!
- Tell It Where Your Stuff Is
- Put a story, picture, or file (like a PDF) in a folder on the computer.
- Write this in a file called play.py (a grown-up can help): python
from llama_index.core import SimpleDirectoryReader documents = SimpleDirectoryReader("your/folder/here").load_data()
- This is like saying, “Hey, look at my cool stuff in this folder!”
- Make a Magic List
- Add this to your play.py file: python
from llama_index.core import VectorStoreIndex index = VectorStoreIndex.from_documents(documents)
- This makes a special list (like a treasure map) so your robot friend can find things fast.
- Add this to your play.py file: python
- Ask Your Question
- Add this to the same file: python
query_engine = index.as_query_engine() answer = query_engine.query("What’s my story about?") print(answer)
- This is you asking your robot friend a question, and he’ll tell you the answer!
- Add this to the same file: python
- Run It and See the Magic
- Ask a grown-up to type this in the command box:
python play.py
- Press Enter, and your robot friend will tell you what he learned!
- Ask a grown-up to type this in the command box:
Extra Fun (Optional)
- If you use a robot voice like OpenAI’s, tell a grown-up to add their “secret key” like this first:
export OPENAI_API_KEY='their-secret-key'
- You can ask more questions by changing the question part—like, “Who’s in my picture?”
That’s it! Now your robot friend knows all about your stuff and can answer your questions like a super smart buddy!