Lightweight retrieval-augmented QA helper for rice pest control guidance using FAISS and OpenAI chat completions.
- Builds embeddings from local PDF references with
all-MiniLM-L6-v2and stores them in FAISS. - Serves concise, context-grounded answers via OpenAI chat completions.
- Robust voice interaction loop for interactive questioning.
- agri.index, chunks.pkl: FAISS index and serialized text chunks generated by
index.py. - index.py: PDF ingestion, chunking (500-word windows), embedding, and index build script.
- app.py: Runtime retrieval and Q&A loop backed by OpenAI with per-session chat memory.
- requirements.txt: Python dependencies.
- Python 3.10+ recommended.
- OpenAI API key (set as
OPENAI_API_KEY). OptionalOPENAI_MODELoverrides the default model. - Source PDFs placed alongside the scripts (filenames in
index.py).
- Create and activate a virtual environment.
- Install deps:
pip install -r requirements.txt. - Create a
.envfile in the project root:OPENAI_API_KEY=your-key-here
Run after placing the PDF files listed in index.py in the project root:
python index.pyArtifacts produced:
- agri.index (FAISS index)
- chunks.pkl (serialized text chunks)
python app.pyType a question; enter exit or press Enter on an empty line to quit.
- Responses strip asterisks and return 2-3 concise bullet phrases when context is available.
- If the question is off-topic, the app replies with: I am sorry, I don't have the information to answer that question.
- Retrieval uses top-3 chunks; adjust
kinretrieve()if you need more or fewer.
to activate virtual env .\venv\Scripts\activate