https://github.com/thomasjanssen-tech/agentic-rag-with-langchain
https://github.com/thomasjanssen-tech/agentic-rag-with-langchain
agentic langchain llm rag retrieval-augmented-generation streamlit supabase
Last synced: 7 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/thomasjanssen-tech/agentic-rag-with-langchain
- Owner: ThomasJanssen-tech
- License: mit
- Created: 2025-02-27T16:24:26.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-04-27T18:21:38.000Z (8 months ago)
- Last Synced: 2025-04-27T19:27:19.597Z (8 months ago)
- Topics: agentic, langchain, llm, rag, retrieval-augmented-generation, streamlit, supabase
- Language: Python
- Homepage: https://thomasjanssen.tech/
- Size: 13.5 MB
- Stars: 14
- Watchers: 2
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
Agentic RAG (Retrieval Augmented Generation) with LangChain and Supabase
Watch the full tutorial on my YouTube Channel
Prerequisites
- Python 3.11+
Installation
1. Clone the repository:
```
git clone https://github.com/ThomasJanssen-tech/Agentic-RAG-with-LangChain.git
cd Agentic RAG with LangChain
```
2. Create a virtual environment
```
python -m venv venv
```
3. Activate the virtual environment
```
venv\Scripts\Activate
(or on Mac): source venv/bin/activate
```
4. Install libraries
```
pip install -r requirements.txt
```
5. Create accounts
- Create a free account on Supabase: https://supabase.com/
- Create an API key for OpenAI: https://platform.openai.com/api-keys
6. Execute SQL queries in Supabase
Execute the following SQL query in Supabase:
```
-- Enable the pgvector extension to work with embedding vectors
create extension if not exists vector;
-- Create a table to store your documents
create table
documents (
id uuid primary key,
content text, -- corresponds to Document.pageContent
metadata jsonb, -- corresponds to Document.metadata
embedding vector (1536) -- 1536 works for OpenAI embeddings, change if needed
);
-- Create a function to search for documents
create function match_documents (
query_embedding vector (1536),
filter jsonb default '{}'
) returns table (
id uuid,
content text,
metadata jsonb,
similarity float
) language plpgsql as $$
#variable_conflict use_column
begin
return query
select
id,
content,
metadata,
1 - (documents.embedding <=> query_embedding) as similarity
from documents
where metadata @> filter
order by documents.embedding <=> query_embedding;
end;
$$;
```
7. Add API keys to .env file
- Rename .env.example to .env
- Add the API keys for Supabase and OpenAI to the .env file
Executing the scripts
- Open a terminal in VS Code
- Execute the following command:
```
python ingest_in_db.py
python agentic_rag.py
streamlit run agentic_rag_streamlit.py
```
Sources
While making this video, I used the following sources:
- https://python.langchain.com/docs/integrations/vectorstores/supabase/
- https://python.langchain.com/docs/integrations/text_embedding/openai/
- https://platform.openai.com/docs/guides/embeddings
- https://www.kaggle.com/code/youssef19/documents-splitting-with-langchain
- https://openai.com/index/new-embedding-models-and-api-updates/
- https://zilliz.com/ai-models/text-embedding-3-small