Hi! Welcome to my Long Context Answer Agent.
This project is an intelligent question-answering agent that leverages the FinWeb semantic search engine to fetch and process a large volume of documents—up to 10,000 per query—to serve as context for answering user questions.
- User Input: The user provides a main question, and a date range (to filter by publication date).
- Slow Search: The system then uses these inputs to search the Finweb API's /slow- search/ endpoint. This endpoint returns an encrypted file (stored on S3) along with an encryption key.
- Generate Embeddings: Downloads and decrypts the file to obtain up to 10,000 search results, then uses the HuggingFace servers to embed the search results.
- USearch Index: Create a USearch index using the HuggingFace embeddings.
- Answer: When a user asks a question, the USearch index is used to retrieve relevant search results. The relevant search results, as well as the user's question, will be sent to a model on OpenRouter to answer the question. The answer generated includes citations that reference the original search results fetched from the slow search endpoint.
- Multi-turn Conversation: Allow the user to ask follow-up questions. The follow-up questions can use the same USearch index.
- Finweb API will be used as the search engine to retrieve context for the user’s query.
- USearch, which allows you to build small, single-file semantic search engines.
- HuggingFace servers to generate the embeddings for the USearch index.
- OpenRouter for LLM model access.
Before usage, you install dependencies:
pip install -r requirements.txtYou must also create a file called keys.env that will contain all your api keys as follows, make sure to remember to replace with your own keys:
FINWEB_V1_API_KEY=your_finweb_api_key_here
OPENROUTER_API_KEY=your_openrouter_api_key_hereFrom there all you need to do is run the code, either in your code editor environment, or through the command line:
python main.pyor
py main.pyFrom there you can use the script as you'd expect, you'll be prompted to put in your question and date range, and any follow up questions in the command line.
If you want a deeper look into the context returned by the FinWeb API, check the user_question.csv file that is created when you use the script.
Big thanks to Nosible, who set this project for me as a technical interview, I had a lot of fun! 🎉