Skip to main content

Lightweight RAG library for internal knowledge systems

Project description

Fullstack RAG AI

Lightweight Retrieval-Augmented Generation (RAG) library for building internal knowledge systems using local documents and LLMs.

This library allows you to:

  • Load documents from PDFs or raw text
  • Automatically chunk and embed documents
  • Store embeddings in a FAISS vector database
  • Ask questions against the knowledge base
  • Use deterministic caching to avoid repeated LLM calls
  • Automatically detect document updates, additions, and deletions

It is designed to use:

  • Ollama LLMs
  • HuggingFace embeddings
  • FAISS vector database

Installation

pip install fullstack-rag-ai

Default Configuration

The library uses a default configuration, but all parameters can be overridden by the user.

DEFAULT_CONFIG = {
    "embedding_model": "sentence-transformers/all-MiniLM-L6-v2",
    "llm_model": "llama3",
    "chunk_size": 5000,
    "chunk_overlap": 500,
    "k": 15
}

Core Workflow

Typical usage flow:

  • Load documents
  • Build or update vector database
  • Ask questions against the database
Documents → Chunking → Embeddings → FAISS → Retrieval → LLM → Answer

Loading Documents

Documents can be loaded either from PDF files or from a list of text strings.

Load From PDFs

from fullstack_rag_lib.ingestion import load_documents

docs = load_documents(path="documents/")

Load From Text List

from fullstack_rag_lib.ingestion import load_documents

texts = [
    "Python is a programming language",
    "FAISS is used for vector similarity search"
]

docs = load_documents(texts=texts)

Function

load_documents(path=None, texts=None)
Parameter Type Description
path str Folder containing PDF files
texts List[str] List of raw text strings

Returns: List[Document]

Updating the Vector Database

This function builds or updates the FAISS vector database.

It automatically handles:

  • New documents
  • Updated documents
  • Deleted documents

Only the necessary parts of the database are rebuilt.

from fullstack_rag_lib.vector_db import sync_vector_db

sync_vector_db(
    documents_path="./data",
    index_path="./vector_db",
)

Function

sync_vector_db(documents_path, index_path, embedding_model=embedding_model)
Parameter Type Description
documents_path str Directory containing PDF files
index_path str Directory where FAISS index is stored
embedding_model str HuggingFace embedding model

This function maintains the following internal files: index.faiss index.pkl documents.bin metadata.bin qa_cache.bin

Asking Questions

Once the vector database exists, you can query it using an LLM.

The system retrieves the most relevant chunks and sends them to the LLM as context.

from fullstack_rag_lib.qa import ask_question

answer = ask_question(
    question="What is FAISS used for?",
    index_path="./vector_db"
)

print(answer)

Function

ask_question(question, index_path, model=model, embedding_model=embedding_model, k=k, debug=False)
Parameter Type Description
question str User question
index_path str Path to vector database
model str Ollama LLM model
embedding_model str HuggingFace embedding model
k int Number of chunks retrieved
debug bool Print retrieved chunks

Returns: str

Deterministic QA Cache

The library includes a smart cache system that prevents unnecessary LLM calls.

Cache keys are generated using: question + retrieved context hash

If:

  • the question is the same

  • the retrieved documents have not changed

The answer is returned directly from cache.

Cache File

qa_cache.bin

Helper Functions

load_binary

Loads a binary pickle file.

load_binary(path)

Returns empty dictionary if file does not exist.

save_binary

Stores data as a binary pickle file.

save_binary(path, data)

compute_cache_key

Creates a deterministic key for caching LLM responses.

compute_cache_key(question, docs)

Uses:

  • Question text
  • Retrieved document content

Example Full Pipeline

from fullstack_rag_lib.vector_db import sync_vector_db
from fullstack_rag_lib.qa import ask_question

# Step 1: Build / Update Vector DB
sync_vector_db(
    documents_path="./data",
    index_path="./vector_db",
)

# Step 2: Ask Questions
answer = ask_question(
    question="Summarize the company onboarding process",
    index_path="./vector_db",
)

print(answer.content)

Changing the Embedding Model

Any HuggingFace embedding model supported by sentence-transformers can be used.

Example:

sync_vector_db(
    documents_path="./data",
    index_path="./vector_db",
    embedding_model="sentence-transformers/all-mpnet-base-v2"
)

The library will automatically download the model through HuggingFace if it is not already installed.

Changing the LLM Model

The LLM model can be changed to any model available in Ollama.

Example:

answer = ask_question(
    question="Explain the onboarding process",
    index_path="./vector_db",
    model="llama3:8b",
    embedding_model="sentence-transformers/all-MiniLM-L6-v2"
)

Other examples:

  • model="mistral"
  • model="phi3"
  • model="llama3:70b"

The only requirement is that the model must be available locally in Ollama.

To install a model:

ollama pull llama3
ollama pull llama3:8b
ollama pull llama3:70b
ollama pull phi3
ollama pull mistral

Important: Rebuilding the Vector Database

If the embedding model changes, the vector database must be rebuilt.

This is because embeddings from different models are not compatible.

Example workflow:

sync_vector_db(
    documents_path="./data",
    index_path="./vector_new_db",
    embedding_model="BAAI/bge-base-en"
)

Alternatively, delete the existing index and rebuild.

Dependencies

  • langchain
  • langchain-community
  • langchain-huggingface
  • langchain-ollama
  • faiss-cpu
  • sentence-transformers
  • pypdf

These libraries allow dynamic usage of:

  • Any HuggingFace embedding model
  • Any Ollama LLM model

Therefore, users do not need to install additional dependencies when switching models.

When changing models:

Change Required Action
LLM model No rebuild needed
Embedding model Rebuild vector database
Chunk size Rebuild vector database

License

MIT License

Author

Fullstack Solutions

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fullstack_rag_ai-0.1.2.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fullstack_rag_ai-0.1.2-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file fullstack_rag_ai-0.1.2.tar.gz.

File metadata

  • Download URL: fullstack_rag_ai-0.1.2.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for fullstack_rag_ai-0.1.2.tar.gz
Algorithm Hash digest
SHA256 eb4791e8004a8ae2231864838ade6e689913abc22856f61e8323964eec6923c0
MD5 3279cd5b8f5fecdc0853537cf18640a8
BLAKE2b-256 76033d872faa2df4de073ab4fc63cd52c7cf36630865c5fe3b536f921c06e74e

See more details on using hashes here.

File details

Details for the file fullstack_rag_ai-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for fullstack_rag_ai-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bd915f3bae9599ef26a68d196c5a58b4d2727ca56f54bffeff5a699b357a23e7
MD5 c349ee64f91cd3d05389959b35c5cdfa
BLAKE2b-256 366aec7e2a4b7a06abc5b9f8716e5ad9a5d3ef5ea5673b1eba8f538248b34cf9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page