Harnessing ChatGPT and LangChain for Sustainable Agriculture

Do you think that AI, like ChatGPT, can change the way researchers approach scientific literature? Check what our colleague Niko Gamulin found out.

Unraveling the potential of large language models and the LangChain framework to optimize literature review, improve understanding of green manure, and contribute to a sustainable agricultural future.


Green manure plays a crucial role in sustainable agriculture by enhancing soil health and fertility. As a data scientist working on the LoginEKO project, I collaborate with agronomists to evaluate the effectiveness of green manure. In this article, we’ll explore the importance of green manure, its benefits, and how leveraging ChatGPT with the LangChain framework helps refine our understanding and optimize its use in large-scale eco-farming.

Understanding Green Manure and Its Importance

Green manure involves growing plants, typically legumes or grasses, and incorporating them into the soil before they mature. This practice enriches the soil with essential nutrients, organic matter, and improves its overall health. Green manure offers numerous benefits, including soil enrichment, improved soil structure, erosion control, weed suppression, and pest control, making it a cornerstone of sustainable agriculture.

The Task: Developing a Model for Estimating Mineralized Nitrogen

As a data scientist, my primary task, in collaboration with agronomists, is to develop a model that can estimate the level of mineralized nitrogen in the soil. Gaining a deeper understanding of mineralization dynamics is vital for enhancing our knowledge of green manure’s effectiveness. To accomplish this, I need to examine scientific literature, focusing on articles that discuss green manure and its benefits.

However, there is an extensive number of scientific articles on green manure, making it essential to prioritize which ones to read. Without the assistance of ChatGPT, this task would be significantly more challenging, as I would have to invest considerable time in sifting through all the articles. By employing ChatGPT, I can effectively narrow down the list of articles on specific topics related to green manure, using it as a starting point to further my research and understanding.

Leveraging ChatGPT with the LangChain Framework for Scientific Research

To optimize my literature review, I utilize ChatGPT, a large language model developed by OpenAI, in conjunction with the LangChain framework. This combination helps me effectively prioritize and digest relevant scientific literature. The process involves several steps, as outlined below:

  1. Reading large articles: Since many articles exceed ChatGPT’s token limit, I first implement logic to split each article into smaller chunks. This ensures the entire content is analyzed without compromising context or information.
  2. Summarizing chunks: For each chunk, I employ ChatGPT to generate a summary, condensing the information while retaining essential details.
  3. Merging summaries: I then merge the summarized chunks, ensuring the final output adheres to the token limit, while still providing a comprehensive understanding of the article.
  4. Storing modified articles in a vector database: Once the summarized articles are prepared, I store them in a vector database, which facilitates efficient retrieval of relevant information.
  5. Implementing the chat engine logic: The LangChain framework enables the development of a chat engine that can interact with the processed articles, extract pertinent information, and provide concise summaries of the findings.

Streamlit app that provides an answer and the references for the given questions.

The above code generates a vector database from the documents.

This function returns an answer based on the processed documents and the references.

By harnessing the power of ChatGPT and LangChain, I can effectively prioritize and understand complex scientific literature on green manure, enhancing my knowledge and contributing to a more sustainable and eco-friendly future for agriculture.


The synergy of ChatGPT and the LangChain framework revolutionizes the way researchers approach scientific literature review in the context of sustainable agriculture. By implementing a step-by-step approach that involves breaking down complex articles, summarizing chunks, merging summaries, storing them in a vector database, and developing an interactive chat engine, data scientists and researchers can gain valuable insights more efficiently. This approach not only saves time but also enhances the overall understanding of intricate scientific concepts like green manure, contributing to the advancement of knowledge and the adoption of sustainable practices in large-scale eco-farming.

The article was originally published in Medium: by our colleague Niko Gamulin.


Green Manure, Legumes, & Crop Rotations: Sustainable Insights

February 23, 2024

Through our sustainable and livestock-free farming methods, we’ve gained valuable insights into utilizing various crops for green manure, as well as the use of legumes in multi-year crop rotation.

Read article

Behind the Scenes: Njamito’s Packaging Adventure

January 15, 2024

Njamito needed a bottle. Between glass, bioplastic and PET, here’s what we picked, and why.

Read article

How Screening Trials Helped Us Find the Best Wheat Varieties

January 12, 2024

Spoiler alert: Not all wheat varieties are great for organic conditions

Read article