joe, (edited ) to ai

Back in January, we started looking at AI and how to run a large language model (LLM) locally (instead of just using something like ChatGPT or Gemini). A tool like Ollama is great for building a system that uses AI without dependence on OpenAI. Today, we will look at creating a Retrieval-augmented generation (RAG) application, using Python, LangChain, Chroma DB, and Ollama. Retrieval-augmented generation is the process of optimizing the output of a large language model, so it references an authoritative knowledge base outside of its training data sources before generating a response. If you have a source of truth that isn’t in the training data, it is a good way to get the model to know about it. Let’s get started!

Your RAG will need a model (like llama3 or mistral), an embedding model (like mxbai-embed-large), and a vector database. The vector database contains relevant documentation to help the model answer specific questions better. For this demo, our vector database is going to be Chroma DB. You will need to “chunk” the text you are feeding into the database. Let’s start there.

Chunking

There are many ways of choosing the right chunk size and overlap but for this demo, I am just going to use a chunk size of 7500 characters and an overlap of 100 characters. I am also going to use LangChain‘s CharacterTextSplitter to do the chunking. It means that the last 100 characters in the value will be duplicated in the next database record.

The Vector Database

A vector database is a type of database designed to store, manage, and manipulate vector embeddings. Vector embeddings are representations of data (such as text, images, or sounds) in a high-dimensional space, where each data item is represented as a dense vector of real numbers. When you query a vector database, your query is transformed into a vector of real numbers. The database then uses this vector to perform similarity searches.

https://i0.wp.com/jws.news/wp-content/uploads/2024/05/Screenshot-2024-05-08-at-2.36.49%E2%80%AFPM.png?resize=665%2C560&ssl=1

You can think of it as being like a two-dimensional chart with points on it. One of those points is your query. The rest are your database records. What are the points that are closest to the query point?

Embedding Model

To do this, you can’t just use an Ollama model. You need to also use an embedding model. There are three that are available to pull from the Ollama library as of the writing of this. For this demo, we are going to be using nomic-embed-text.

Main Model

Our main model for this demo is going to be phi3. It is a 3.8B parameters model that was trained by Microsoft.

LangChain

You will notice that today’s demo is heavily using LangChain. LangChain is an open-source framework designed for developing applications that use LLMs. It provides tools and structures that enhance the customization, accuracy, and relevance of the outputs produced by these models. Developers can leverage LangChain to create new prompt chains or modify existing ones. LangChain pretty much has APIs for everything that we need to do in this app.

The Actual App

Before we start, you are going to want to pip install tiktoken langchain langchain-community langchain-core. You are also going to want to ollama pull phi3 and ollama pull nomic-embed-text. This is going to be a CLI app. You can run it from the terminal like python3 app.py "<Question Here>".

You also need a sources.txt file containing the URLs of things that you want to have in your vector database.

So, what is happening here? Our app.py file is reading sources.txt to get a list of URLs for news stories from Tuesday’s Apple event. It then uses WebBaseLoader to download the pages behind those URLs, uses CharacterTextSplitter to chunk the data, and creates the vectorstore using Chroma. It then creates and invokes rag_chain.

Here is what the output looks like:

https://i0.wp.com/jws.news/wp-content/uploads/2024/05/Screenshot-2024-05-08-at-4.09.36%E2%80%AFPM.png?resize=1024%2C845&ssl=1

The May 7th event is too recent to be in the model’s training data. This makes sure that the model knows about it. You could also feed the model company policy documents, the rules to a board game, or your diary and it will magically know that information. Since you are running the model in Ollama, there is no risk of that information getting out, too. It is pretty awesome.

Have any questions, comments, etc? Feel free to drop a comment, below.

https://jws.news/2024/how-to-build-a-rag-system-using-python-ollama-langchain-and-chroma-db/

kjaymiller, to generativeAI
@kjaymiller@mastodon.social avatar

So tomorrow I’m doing this thing.

Instead of picking winners in AI I prefer tools that allow you to explore and quickly adapt so we’re going to be walking through how I prepared my podcast transcriptions to be used in a RAG application using and .

Recordings for registered folks only so sign up even if you can’t attend live. https://hachyderm.io/

daniel_js_craft, to generativeAI
@daniel_js_craft@mastodon.social avatar

Fun fact about the Langchain's logo. The parrot and a chain link were inspired by people calling LLMs stochastic parrots. Models mimic human writing but don't really understand what they're saying.
#Langchain serves to "chain" the "parrots" together 😃
#llm #javascript #webdev

ramikrispin, to llm
@ramikrispin@mstdn.social avatar

RAG from Scratch with LangChain 🦜👇🏼

FreeCodeCamp released today a new course on building RAG from scratch with LangChain. The course, which is by Lance Martin from LangChain, focuses on the foundations of Retrieval Augmented Generation (RAG).

Course 📽️: https://www.youtube.com/watch?v=sVcwVQRHIc8
Code 🔗: https://github.com/langchain-ai/rag-from-scratch

daniel_js_craft, to LLMs
@daniel_js_craft@mastodon.social avatar

Google Gemini aims for a 10 mil tokens context. It's so large that you can put books, docs, videos. They all fit in this context size. Will this replace RAG?

Don't think so because:
-💸 money; you still pay per token
-🐢 slow response time
-🐞 a huge context is hard to debug

daniel_js_craft, to javascript
@daniel_js_craft@mastodon.social avatar
ramikrispin, to llm
@ramikrispin@mstdn.social avatar

RAG From Scratch - Langchain Tutorial 🦜👇🏼

The RAG From Scratch is a crash course by Lance Martin from LangChain focusing on the foundations of Retrieval Augmented Generation (RAG). This tutorial covers the process of index, retrieval, and generation of a query from scratch 🚀.

Video 📽️: https://www.youtube.com/playlist?list=PLfaIDFEXuae2LXbO1_PKyVJiQ23ZztA0x
Code 🔗: https://github.com/langchain-ai/rag-from-scratch

Image credit: Tutorial slides

#llm #rag #DataScience #langchain #mahcinelearning #mlops

thomasrenkert, to generativeAI German
@thomasrenkert@hcommons.social avatar

Is there any tutorial (or just better docs) on how to use with graph databases ()like or to build a with data? Maybe somebody even knows how to use LangChain together with ?

@machinelearning

textvr, to generativeAI German
@textvr@berlin.social avatar

Demo time: WiFi is not working, changing to video. Demo gods still in a bad mood at
There are a lot of good videos on YouTube about doing RAG with Langchain, also with open-soure models.

textvr, to generativeAI German
@textvr@berlin.social avatar

Stefano Fancello is talking about , an open-source Python-based toolkit for Retrieval Augmentation Generation . It helps preparing your own data as a context for a question you send to a Large Language Model . Langchain tools can ingest all kinds of document formats, split documents into Chunks, and create so called and send it to the LLM.

ramikrispin, to generativeAI
@ramikrispin@mstdn.social avatar

(1/2) LangGraph Crash Course with code examples 🚀

This short tutorial, by Sam Witteveen, provides a short intro to LangGraph 🦜, the LangChain new 🐍 library. The tutorial focuses on the foundations of LangGraph - StateGraph, nodes and edges, agent executer, and agent supervisor.

Tutorial 📽️: https://www.youtube.com/watch?v=PqS1kib7RTw

ramikrispin,
@ramikrispin@mstdn.social avatar
ramikrispin, to python
@ramikrispin@mstdn.social avatar

LangChain GEN AI Tutorial 🚀

A new course for LangChain by Krish Naik and freeCodeCamp. The course focuses on the functionality of LangChain with a practical example of setting up a chatbot using Streamlit with the following LLMs:
✅ OpenAI's GPT-3.5 and GPT-4
✅ Llama2
✅ Google Gemini Pro
✅ Working with Hugingfaces models

📽️: https://www.youtube.com/watch?v=x0AnCE9SE4A

#python #langchain #llm #datascience #MachineLearning #deeplearning

ramikrispin, to python
@ramikrispin@mstdn.social avatar

A crash course to LangGraph 🦜🔗

The LangGraph series provides a short introduction to the LangGraph 🦜🔗 library. This includes the following topics:
✅ The library core functionality
✅ Agend executor
✅ Dynamicly returning a tool output directly
✅ Managing agent steps

📽️: https://www.youtube.com/playlist?list=PLfaIDFEXuae16n2TWUkKq5PgJ0w6Pkwtg

derenrich, to generativeAI

Demo of using to query @wikidata using natural language https://nbviewer.org/urls/d.erenrich.net/upload/Wikidata_Langchain.ipynb I think this approach can beat SPARQL in many basic use cases. I'm hoping to get this merged into langchain upstream.

ramikrispin, to llm
@ramikrispin@mstdn.social avatar

LangChain.js crash course 🚀👇🏼

FreeCodeCamp released a crash course for LangChain.js, a JavaScript version of LangChain for running LLMs in applications. The course, by Tom Chant, focuses on integrating LLMs in JS applications using the OpenAI API.

➡️📽️: https://www.youtube.com/watch?v=HSZ_uaif57o

#llm #js #LangChain #openai

ramikrispin, to llm
@ramikrispin@mstdn.social avatar

LangChain 🦜 crash course for beginners by freeCodeCamp 👇🏼

https://youtu.be/lG7Uxts9SXs?si=XlFZzrKBw5cVt_2Y

#llm #langchain #nlp #python #deeplearning #MachineLearning #DataScience

habuma, to generativeAI

In my two most recent videos, I introduced you to some of the basics of Spring AI. Now, let's take a step back and look at LangChain, one of the projects that inspired Spring AI.

https://youtu.be/fo0BUkDSUTQ

jd7h, to generativeAI
@jd7h@fosstodon.org avatar

Today I took a first look at LangSmith, a new platform for LLM production pipelines by LangChain.
I can't hook it up to a working pipeline yet because it's in closed beta, but it surely looks ambitious. It should make it easier to do logging, monitoring, debugging and evaluating pipelines (chains) against each other. It's tightly integrated with LangChain but it should support other frameworks/models as well.

https://www.langchain.com/langsmith

#langsmith #langchain #llms #generativeai #mlops #ai

kellogh, to generativeAI
@kellogh@hachyderm.io avatar

i wish there were some generic solution to DAGs. is a heavily OOP API. it's great if you want to swap component B for component A, but you're pretty much on your own if you want programs to flow differently. e.g. chat is treated entirely different than question-answer, and creating a new flow means getting neck deep in internal langchain APIs. i wish the components were loosely coupled so i could quickly rearrange the flow

ramikrispin, to opensource
@ramikrispin@mstdn.social avatar

Prompt engineering with Pezzo 🚀👇🏼

Pezzo is an platform that provides tools for prompt engineering at scale. That includes features for managing prompts, creating workflows, deploying, and observability.

It supports prompts with tools such as , , AI21labs, etc., and is based on node.js and runs on .

License: Apache 2.0 🦄

Resources 📚
Source code: https://github.com/pezzolabs/pezzo
Documentation: https://docs.pezzo.ai/docs/intro

smach, (edited ) to generativeAI
@smach@fosstodon.org avatar

The LangChain LLM framework is only available in Python and JavaScript. But if you're an R user, @jayeung12 shows how to incorporate LangChain Python code into an R script with the {reticulate} 📦. This lets you include in an workflow.
https://jason-yeung.netlify.app/posts/2023_5_26/

jbzfn, to random
@jbzfn@mastodon.social avatar

"If you google around enough, you’ll find people talking about using LangChain to chain together LLM calls and get better outputs. However, chaining calls to an LLM just makes the latency problem with LLMs worse, which is a nonstarter for us. But even if it wasn’t, we have the potential to get bitten by compound probabilities."
@honeycombio

#LLM #LangChain #PromptEngineering
https://www.honeycomb.io/blog/hard-stuff-nobody-talks-about-llm

kurtseifried, to random

episode 377 with myself and @joshbressers is out https://opensourcesecurity.io/2023/05/28/episode-377-the-world-is-changing-too-fast-for-humans-to-understand/ TL;DR: you will learn why you hate change and why resistance is futile.

hobs,
@hobs@mstdn.social avatar

@kurtseifried

Loved your latest podcast on exponential change and the inability of our to keep up.
Perhaps fight fire with fire - an AI information bodyguard that you trust. Basically Siri with actually doing what you ask it to do instead of faking it and sharing your data with predatory BigTech.
Daniel Miessler had some ideas but he's too techno optimist for me.



@joshbressers

  • All
  • Subscribed
  • Moderated
  • Favorites
  • JUstTest
  • GTA5RPClips
  • DreamBathrooms
  • InstantRegret
  • magazineikmin
  • khanakhh
  • Youngstown
  • ngwrru68w68
  • slotface
  • everett
  • rosin
  • thenastyranch
  • kavyap
  • tacticalgear
  • megavids
  • cisconetworking
  • normalnudes
  • osvaldo12
  • ethstaker
  • mdbf
  • modclub
  • Durango
  • tester
  • provamag3
  • cubers
  • Leos
  • anitta
  • lostlight
  • All magazines