Skip to main content

A Python library for Retrieval-Augmented Generation (RAG) capabilities in LLM applications.

Project description

fabricatio-rag

MIT Python Versions PyPI Version PyPI Downloads PyPI Downloads Bindings: PyO3 Build Tool: uv + maturin

A Python library for Retrieval-Augmented Generation (RAG) capabilities in LLM applications.

📦 Installation

This package is part of the fabricatio monorepo and can be installed as an optional dependency using either pip or uv:

pip install fabricatio[rag]
# or
uv pip install fabricatio[rag]

For a full installation that includes this package and all other components of fabricatio:

pip install fabricatio[full]
# or
uv pip install fabricatio[full]

🔍 Overview

Provides tools for:

  • Document embedding and vector storage using LanceDB This feature uses the LanceDB vector database to store document embeddings. Document embeddings are numerical representations of text documents that capture their semantic meaning. The library stores embeddings in LanceDB, which provides efficient storage and retrieval with automatic indexing.
  • Semantic search and context retrieval The semantic search and context retrieval feature allows users to search for relevant documents based on the meaning of their queries. It uses nearest-neighbor search on stored embeddings to find documents that are semantically similar to the query.
  • Reranking with TEI (Text Embeddings Inference) services The TEI integration enables document reranking. TEI services provide pre-trained models that can rerank texts based on relevance to a query. This allows for state-of-the-art reranking without managing model training locally.
  • Database injection workflows The database injection workflows handle inserting documents into LanceDB, including vector conversion, collection/table creation, data indexing, and error handling.
  • Asynchronous RAG execution patterns The asynchronous RAG execution patterns allow the library to perform multiple RAG tasks concurrently without blocking the main thread.

Built on top of Fabricatio's agent framework with support for asynchronous execution and Rust extensions.

🧩 Usage Example

from fabricatio_rag import VectorStoreService, VectorStoreTable, StoreDocument


async def search_knowledge():
    # Initialize database connection (LanceDB URI, e.g. /tmp/lancedb or s3://bucket/path)
    service = await VectorStoreService.connect("data/lancedb")

    # Create a table with embedding dimension 1536 (OpenAI text-embedding-3-small)
    table = await service.create_table("science_papers", ndim=1536)

    # Add documents
    docs = [
        StoreDocument(content="Climate change severely impacts coral reef ecosystems...", vector=[...]),
        StoreDocument(content="Ocean acidification reduces shell thickness in mollusks...", vector=[...]),
    ]
    await table.add_documents(docs)

    # Search for relevant documents
    results = await table.search_document(embedding=[...], limit=3)

    print("Top 3 relevant documents:")
    for result in results:
        print(f"- {result.content[:80]}...")

📁 Structure

fabricatio-rag/
├── actions/          - Data injection workflows
├── capabilities/    - Core RAG functionality
├── models/           - Document models
└── rust.pyi          - Rust extension interfaces

🔗 Dependencies

Core dependencies:

  • lancedb - Vector database integration
  • fabricatio-core - Core interfaces and utilities

Rust extensions:

  • LanceDB table management via PyO3 bindings
  • TEI reranking via thryd router

📄 License

MIT – see LICENSE

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

fabricatio_rag-0.4.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file fabricatio_rag-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: fabricatio_rag-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fabricatio_rag-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eb4dc35556ba722a8c9b296b999bfe793ba91d24f550909bd651e86195246434
MD5 07698043638019f8139789e08cc60afd
BLAKE2b-256 3357abc02819163918a28e7b89068b5077ea790e5bcf8fb90efa7bbf86b6157a

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