Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: full-stack RAG pipeline for PDF ingestion and contextual chat capabilities #28

Merged
merged 19 commits into from
Nov 18, 2024

Conversation

Nyumat
Copy link
Member

@Nyumat Nyumat commented Nov 9, 2024

This pull request implements a full-stack retrieval-augmented generation (RAG) ingestion pipeline and querying capability. As the core functionality of Beavs AI, this will be a constant work in progress. Although, we can finally say: We did it 🚀

Demo

beavsai_demo.mov

How It Works

PDF Upload Workflow

  1. File Upload: User uploads a PDF via the UI.
  2. Presigned URL: Backend generates a Cloudflare R2 presigned URL for secure access.
  3. File Parsing: PDF is parsed into text chunks using WebPDFLoader.
  4. Chunking: Text is split into chunks with RecursiveCharacterTextSplitter.
  5. Embedding Creation: Chunks are embedded with OpenAIEmbeddings.
  6. Pinecone Storage: Embeddings are upserted into Pinecone.
  7. Database Update: documentIds and isIndexed fields in the course_materials table are updated.

Chat Context Workflow

  1. File Selection: User selects a previously uploaded PDF when starting a chat.
  2. Message Retrieval: Latest user message is retrieved for querying.
  3. Embedding Search: Message is embedded and searched in Pinecone for relevant chunks.
  4. Context Preparation: Retrieved chunks are combined into a file context.
  5. Chat Session: The chat session starts using from the PDF metadata (fileName).

Key Changes

  • Dependencies: Added @langchain/pinecone and removed langchain.
  • Schema: Added documentIds and isIndexed fields to course_materials.
  • API Updates: Enhanced embeddings and chat routes for PDF processing and context retrieval.
  • Components: Updated chat components and actions for file-based context support.
  • Utilities: Added PDF parsing utilities and improved Pinecone and OpenAI clients.

Next Steps

  • Improve error handling and performance.
  • Support multi-tenant use relevant info.
  • Support sources for the AI response.
  • Allow instant chat to query across all documents.

Note

This foundational RAG pipeline allows Beavs AI to provide document-based contextual chats, enhancing the user interactions and responses.

@Nyumat Nyumat added the critical Breaking change/feature label Nov 9, 2024
@Nyumat Nyumat self-assigned this Nov 9, 2024
@Nyumat Nyumat linked an issue Nov 9, 2024 that may be closed by this pull request
@Nyumat
Copy link
Member Author

Nyumat commented Nov 10, 2024

Going to clean up the code a bit to help prepare for our next meeting, where we'll do a deep dive of this implementation!

@owenkrause owenkrause merged commit 84fbe2b into main Nov 18, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
critical Breaking change/feature
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Research and set up vector database system
2 participants