Stock vs. Stock uses Llama 3.1 405B hosted on SambaNova to compare any pair of S&P 500 stocks based on a top 10 investment factor and gives an investment recommendation. The comparison is based on RAG with the 2 companies' recent 2024 financial statements (8-K, 10-K, 10-Q) filed with the SEC, which are embedded using OpenAI as vectors in TiDB. Also, a summary of the whole analysis and an optional report are generated by Llama. The user can also enter their own custom investment factors to do the stock vs. stock comparison, such as comparing AI strategy.
TiDB was chosen as the vector store because its free tier includes up to five clusters, each up to 5GB vector data, and for this project I needed over 7GB total for vector and metadata storage. The S&P 500 companies' financial statements are loaded to the vector store as described in the project README. The companies are split between 2 clusters, and for a given company the app does a vector search in the cluster configured for it. For example, the user may choose to compare 2 companies which have their data stored in separate clusters. The app caches the 2 connections to the clusters for performance, with reconnect as needed. To minimize the overhead of RAG in the agentic workflow the vector search is done using filters: ticker, date, and filing type.
All prompts used by the app are stored in 15 prompt files. This allows prompt tweaks without touching the code. I engineered the prompts and set the max token size for Llama 3.1 405B. If the Llama version is changed, keep in mind the prompts may need re-tweaking.
There has been debate about the trustworthiness of AI generated investment recommendations and if they are better than a coin toss. By grounding the recommendations in the official and public financial statements of US traded companies, I propose Stock vs. Stock is better than a coin toss.
Built With
- edgar
- gradio
- langchain
- llama-3.1-405b
- openai-embedding
- python
- sambanova
- tidb
- vector-search
- yfinance

Log in or sign up for Devpost to join the conversation.