{"id":14064871,"url":"https://github.com/streamlit/example-app-langchain-rag","last_synced_at":"2025-04-10T01:33:16.810Z","repository":{"id":226308207,"uuid":"765925968","full_name":"streamlit/example-app-langchain-rag","owner":"streamlit","description":"Streamlit app demonstrating using LangChain and retrieval augmented generation with a vectorstore and hybrid search","archived":false,"fork":false,"pushed_at":"2024-08-12T19:19:14.000Z","size":732,"stargazers_count":107,"open_issues_count":3,"forks_count":56,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-24T03:11:32.216Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/streamlit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-01T22:26:37.000Z","updated_at":"2025-03-22T15:50:31.000Z","dependencies_parsed_at":"2024-04-01T17:42:45.940Z","dependency_job_id":"3f23fb87-4316-4aa1-80d2-4d897811eff0","html_url":"https://github.com/streamlit/example-app-langchain-rag","commit_stats":{"total_commits":25,"total_committers":2,"mean_commits":12.5,"dds":0.07999999999999996,"last_synced_commit":"83d150474fd50d8dae19df2ecf2b57c061bfa497"},"previous_names":["streamlit/example-app-langchain-rag"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streamlit%2Fexample-app-langchain-rag","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streamlit%2Fexample-app-langchain-rag/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streamlit%2Fexample-app-langchain-rag/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streamlit%2Fexample-app-langchain-rag/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/streamlit","download_url":"https://codeload.github.com/streamlit/example-app-langchain-rag/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248140757,"owners_count":21054351,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-13T07:04:08.466Z","updated_at":"2025-04-10T01:33:16.774Z","avatar_url":"https://github.com/streamlit.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"\n# LangChain and Streamlit RAG\n\n## Demo App on Community Cloud\n\n[![Streamlit App](https://static.streamlit.io/badges/streamlit_badge_black_white.svg)](https://st-lc-rag.streamlit.app/)\n\n\n## Quickstart\n\n### Setup Python environment\n\nThe Python version used when this was developed was 3.10.13\n\n\n```bash\npython -mvenv .venv\nsource .venv/bin/activate\npip install -U pip\npip install -r requirements.txt\n```\n\nIf you run into issues related to hnswlib or chroma-hnswlib while installing requirements you may need to install system package for the underlying package.\n\nFor example, on Ubuntu 22.04 this was needed before pip install of hnswlib would succeed.\n\n```bash\nsudo apt install python3-hnswlib\n```\n\n### Setup .env file with API tokens needed.\n\n```\nOPENAI_API_KEY=\"\u003cPut your token here\u003e\"\nHUGGINGFACEHUB_API_TOKEN=\"\u003cPut your token here\u003e\"\n```\n\n### Setup Streamlit app secrets.\n\n#### 1. Set up the .streamlit directory and secrets file.\n\n```bash\nmkdir .streamlit\ntouch .streamlit/secrets.toml\nchmod 0600 .streamlit/secrets.toml\n```\n\n#### 2. Edit secrets.toml\n\n**Either edit `secrets.toml` in you favorite editor.**\n\n```toml\nOPENAI_API_KEY=\"\u003cPut your token here\u003e\"\nHUGGINGFACEHUB_API_TOKEN=\"\u003cPut your token here\u003e\"\n```\n\n**Or, you can just reuse .env contents from above.**\n\n```bash\ncat \u003c .env \u003e\u003e .streamlit/secrets.toml\n```\n\n### Verify Environment\n\n1. Check that LangChain dependencies are working.\n\n```bash\npython basic_chain.py\n```\n\n2. Check that Streamlit and dependencies are working.\n\n```bash\nstreamlit run streamlit_app.py\n```\n\n3. Run Individual Example Programs\n\nThe most of the Python source files besides `streamlit_app.py` have a main defined\nso that you can execute them directly as an example or test.\n\nFor example, the main in `ensemble.py` will use context from an online version of the book [*The Problems of Philosophy* by Bertrand Russell](https://www.gutenberg.org/ebooks/5827.html.images)\nto answer \"What are the key problems of philosophy according to Russell?\"\n\n```bash\npython ensemble.py\n```\n\n\u003e    Split into 313 chunks\n\u003e    According to Russell, the key problems of philosophy include the uncertainty of knowledge, the limitations of metaphysical reasoning, and the inability to provide definite answers to fundamental questions. Philosophy aims to diminish the risk of error, but cannot eliminate it entirely due to human fallibility. The value of philosophy lies in its ability to challenge common sense beliefs and lead to the exploration of complex problems.\n\n\n\n## Example Queries for Streamlit App\n\n### Example 1: Metabolic Rate\n\n**Question:**\nIf I am an 195 lb male, what should my calorie intake be to lose 1 lb a week based on what you know about my basal metabolic rate?\n\n**Answer:**\nTo calculate the calorie intake for a 195 lb male to lose 1 lb per week based on their basal metabolic rate, we can use the estimated BMR values provided in the context.\n\nFor a 190 lb male, the estimated BMR is around 2,280 calories per day. To lose 1 lb per week, a general rule of thumb is to create a calorie deficit of about 500 calories per day.\n\nTherefore, to lose 1 lb per week, a 195 lb male should aim to consume around 1,780 calories per day (2,280 calories - 500 calories). This calorie intake, combined with regular physical activity, can help achieve a sustainable weight loss goal.\n\n### Example 2: Recipes\n\nNOTE: to use this example, copy the `example/us_army_recipes.txt` file into the `data` directory. It is left out by default because it significantly increases the resources used over the other examples.\n\n**Question:**\nHow do I make salmon croquettes according to the recipes I provided you?\n\n**Answer:**\nTo make salmon croquettes based on the recipes shared, you can follow these steps:\n\nIngredients:\n\n- 4 cans of salmon\n- 4 pounds of cold boiled potatoes\n- 2 eggs\n- Salt and pepper to taste\n- Cracker dust for coating\n- Oil for frying\n\nInstructions:\n\n1. Drain the canned salmon and remove any bones or skin.\n2. In a large bowl, mash the salmon and boiled potatoes together.\n3. Add the eggs, salt, and pepper to the mixture and combine well.\n4. Shape the mixture into small cakes about 2 inches in diameter.\n5. In a separate bowl, beat the remaining eggs with a little milk to create an egg batter.\n6. Dip each salmon cake into the egg batter, then coat it with cracker dust.\n7. Heat oil in a pan for frying.\n8. Fry the salmon croquettes in the hot oil until they are golden brown on all sides.\n9. Once cooked, remove them from the oil and place them on a paper towel to drain any excess oil.\n10. Serve the salmon croquettes hot and enjoy!\n\nI hope these instructions help you make delicious salmon croquettes! Let me know if you need any more assistance.\n\n\n## Example Data Used\n\n* The file `examples/nutrients_csvfile.csv` is from the Kaggle Dataset [Nutritional Facts for most common foods](https://www.kaggle.com/datasets/niharika41298/nutrition-details-for-most-common-foods/)\nshared under the [CC0: Public Domain](https://creativecommons.org/publicdomain/zero/1.0/) license.\n* The file `examples/us_army_recipes.txt` is in the public domain, and was retrieved from Project Gutenberg at [Recipes Used in the Cooking Schools, U. S. Army by United States. Army](https://www.gutenberg.org/ebooks/65250).\n* The file `examples/healthy_meal_10_tips.pdf` was published by thes USDA, Center for Nutrition Policy and Promotion and was retrieved from Wikimedia  Commons, and is in the public domain.\n[See page for author, Public domain, via Wikimedia Commons](https://commons.wikimedia.org/wiki/File:Build_a_healthy_meal_10_tips_for_healthy_meals_(IA_CAT31299650).pdf).\n* The file `examples/mal_boole.pdf` is in the public domain. Boole, G. (1847, January 1). The Mathematical Analysis of Logic. Retrieved from Project Gutenberg at https://www.gutenberg.org/ebooks/36884.\n* The file `examples/grocery.md` is just a grocery list.\n\n## References\n\n\nGordon V. Cormack, Charles L A Clarke, and Stefan Buettcher. 2009. [Reciprocal rank fusion outperforms condorcet and individual rank learning methods](https://dl.acm.org/doi/10.1145/1571941.1572114). In Proceedings of the 32nd international ACM SIGIR conference on Research and development in information retrieval (SIGIR '09). Association for Computing Machinery, New York, NY, USA, 758–759. \u003chttps://doi.org/10.1145/1571941.1572114\u003e.\n\nJiang, A. Q., Sablayrolles, A., Mensch, A., Bamford, C., Singh Chaplot, D., de las Casas, D., … \u0026 El Sayed, W. (2023). [Mistral 7B](https://arxiv.org/abs/2310.06825). arXiv e-prints, arXiv-2310. \u003chttps://doi.org/10.48550/arXiv.2310.06825\u003e.\n\nLewis, P., Perez, E., Piktus, A., Petroni, F., Karpukhin, V., Goyal, N., … \u0026 Kiela, D. (2020). [Retrieval-augmented generation for knowledge-intensive nlp tasks](https://arxiv.org/abs/2005.11401). Advances in Neural Information Processing Systems, 33, 9459–9474.\n\nLiu, N. F., Lin, K., Hewitt, J., Paranjape, A., Bevilacqua, M., Petroni, F., \u0026 Liang, P. (2024). [Lost in the middle: How language models use long contexts](https://arxiv.org/abs/2307.03172). Transactions of the Association for Computational Linguistics, 12, 157–173.\n\nRobertson, S., \u0026 Zaragoza, H. (2009). [The probabilistic relevance framework: BM25 and beyond](https://dl.acm.org/doi/10.1561/1500000019). Foundations and Trends® in Information Retrieval, 3(4), 333–389. \u003chttps://doi.org/10.1561/1500000019\u003e\n\nThibault Formal, Benjamin Piwowarski, and Stéphane Clinchant. 2021. [SPLADE: Sparse Lexical and Expansion Model for First Stage Ranking](https://dl.acm.org/doi/10.1145/3404835.3463098). In Proceedings of the 44th International ACM SIGIR Conference on Research and Development in Information Retrieval (SIGIR '21). Association for Computing Machinery, New York, NY, USA, 2288–2292. \u003chttps://doi.org/10.1145/3404835.3463098\u003e.\n\nTunstall, L., Beeching, E., Lambert, N., Rajani, N., Rasul, K., Belkada, Y., … \u0026 Wolf, T. (2023). Zephyr: Direct Distillation of LM Alignment. arXiv e-prints, arXiv-2310. \u003chttps://doi.org/10.48550/arXiv.2310.16944\u003e.\n\n## Misc Notes\n\n- There is an issue with newer langchain package versions and streamlit chat history, see https://github.com/langchain-ai/langchain/pull/18834\n  - This one reason why a number of dependencies are pinned to specific values.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstreamlit%2Fexample-app-langchain-rag","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstreamlit%2Fexample-app-langchain-rag","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstreamlit%2Fexample-app-langchain-rag/lists"}