Skip to main content

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

Project description

fabricatio-rag

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:

pip install fabricatio[rag]

Or install all components:

pip install fabricatio[full]

🔍 Overview

Provides tools for:

  • Document embedding and vector storage using Milvus This feature uses the Milvus vector database to store document embeddings. Document embeddings are numerical representations of text documents that capture their semantic meaning. The library first converts text documents into embeddings using appropriate embedding models. These embeddings are then stored in Milvus, which provides efficient storage and retrieval capabilities. For example, it can handle large - scale document collections and perform fast similarity searches.
  • 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 the stored document embeddings in Milvus to find documents that are semantically similar to the query. This is more powerful than traditional keyword - based search as it can understand the intent behind the query. For example, if a user searches for "effects of pollution on wildlife", it can retrieve documents that discuss related concepts even if the exact keywords are not present.
  • Integration with TEI (Text Embeddings Inference) services The integration with TEI services enables the generation of text embeddings. TEI services provide pre - trained models that can convert text into embeddings. The library can send text data to the TEI service and receive the corresponding embeddings. This allows for the use of state - of - the - art embedding models without having to manage the model training and inference process locally.
  • Database injection workflows The database injection workflows are responsible for inserting new documents into the Milvus database. It takes care of the process of converting the documents into embeddings, and then inserting them into the appropriate collections in Milvus. This includes handling tasks such as collection 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. This is useful for improving the performance and responsiveness of the application. For example, it can handle multiple user queries simultaneously, reducing the overall response time.

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

🧩 Usage Example

from fabricatio_rag.capabilities.rag import RAG
The `RAG` class is the core component of the library. It provides methods for performing retrieval - augmented generation tasks. It interacts with the Milvus database for document retrieval and uses the generated embeddings to augment the generation process.
from fabricatio_rag.models.rag import MilvusDataBase
The `MilvusDataBase` class represents the connection to the Milvus vector database. It provides methods for creating collections, inserting documents, and performing searches. It abstracts the low - level details of working with Milvus, making it easier to use in the application.


async def search_knowledge():
    # Initialize database connection
    db = MilvusDataBase(collection_name="science_papers")
    This line initializes a connection to the Milvus database with a specific collection named "science_papers". The collection is where the document embeddings will be stored and retrieved from.

    # Initialize RAG capability
    rag = RAG(db)
    This line creates an instance of the `RAG` class, passing in the `MilvusDataBase` object. This allows the `RAG` class to interact with the Milvus database for document retrieval.

    # Search for relevant information
    results = await rag.retrieve("climate change impact on coral reefs", limit=3)
    The `retrieve` method of the `RAG` class is used to perform a semantic search in the Milvus database. It takes a query string and a limit as parameters. In this example, it searches for documents related to "climate change impact on coral reefs" and returns the top 3 relevant documents.

    print("Top 3 relevant documents:")
    for result in results:
        print(f"- {result['title']}")
        print(f"  Relevance: {result['score']:.2f}")
        print(f"  Snippet: {result['text'][:150]}...")

📁 Structure

fabricatio-rag/
├── actions/          - Data injection workflows
├── capabilities/     - Core RAG functionality
├── models/           - Database and query models
├── proto/            - TEI service definitions
└── rust.pyi          - Rust extension interfaces

🔗 Dependencies

Core dependencies:

  • pymilvus>=2.5.4 - Vector database integration
  • fabricatio-core - Core interfaces and utilities

Rust extensions:

  • TEI client bindings
  • Protobuf definitions for gRPC communication

📄 License

MIT – see LICENSE

GitHub: github.com/Whth/fabricatio

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 Distributions

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

fabricatio_rag-0.1.7-cp313-cp313-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.13Windows x86-64

fabricatio_rag-0.1.7-cp313-cp313-manylinux_2_34_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

fabricatio_rag-0.1.7-cp313-cp313-manylinux_2_34_aarch64.whl (1.6 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

fabricatio_rag-0.1.7-cp313-cp313-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

fabricatio_rag-0.1.7-cp312-cp312-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.12Windows x86-64

fabricatio_rag-0.1.7-cp312-cp312-manylinux_2_34_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

fabricatio_rag-0.1.7-cp312-cp312-manylinux_2_34_aarch64.whl (1.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

fabricatio_rag-0.1.7-cp312-cp312-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file fabricatio_rag-0.1.7-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for fabricatio_rag-0.1.7-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 69ef3ba60788745af7888a5f074b9ec91b956e646efb6f2247d8dae80c00de09
MD5 d36519ab58b087ad2d77639f270afacc
BLAKE2b-256 bab6967a082626fa6ce745cdff077d301eb9c46a68faa82611f4ef0c9697c13e

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.7-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for fabricatio_rag-0.1.7-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 2da01e4b0d868b1275613a9f335a2061a0e6082c115bde69953978eebce7fe91
MD5 89ece450a2ac9fdcebaa77132bff74de
BLAKE2b-256 3a07b3a4a61094fd0fddf3d20ee3d5e778e2402974b02fe222d6df372bcc20fd

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.7-cp313-cp313-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for fabricatio_rag-0.1.7-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 578a11145e30926c560195313754738d7835fac49a3709603d98926ca34ab0dc
MD5 9434e56812550270f7d880cf40995d0f
BLAKE2b-256 d9cc83657d7429d6d9768f2fa0803c4acf026c286805b1c75d345f344b6a7966

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.7-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fabricatio_rag-0.1.7-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8c566c016d9b7cc4a09a7c1ec95caa7dc06fcabb8833365c0b2099b62d29df2c
MD5 87b51770e1152fe0dc093d242c4a6803
BLAKE2b-256 8dd932d8a94d2556a68d130d74556acae51d43afd2b53ec3401f355a71e4a444

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.7-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for fabricatio_rag-0.1.7-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 3cab9405bd834d77e75718224052a4e9b54984052463f2bf5ab2590c41af7b69
MD5 5a32f5518a75cd2e701e980402804124
BLAKE2b-256 1511b0f1cd1417ef1cbaea374b1a455261f90bc7c7bf29a808e0633afd564bd0

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.7-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for fabricatio_rag-0.1.7-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f10f80f24ed22337859a2e228ac0a078850839b761f465d9b05ad71411e9f037
MD5 57783fe6921ee28d8dcdbc3835faa5c1
BLAKE2b-256 5c10ba4253e9e38f23cc00647c2ea311ff9634c275b9e4bfeaa80edbc27d7f11

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.7-cp312-cp312-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for fabricatio_rag-0.1.7-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 413130b43ff9f7bcad91030f3cbe51384856004d2f15cedced5eab83e6121580
MD5 3fa2862a2e5c4c6f9eeb3d903ee25a6c
BLAKE2b-256 aa71082025ecdeaaa86e522937c120e8052cd86f90348550515ac74473bc53af

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.7-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fabricatio_rag-0.1.7-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e70c69efe34745d78b1683afcdc61f777c57aad00f5d73e23adb8f5fb119cea7
MD5 436235fd7284535bacb72772435ff018
BLAKE2b-256 6f6b769488481f8b98ba327d3b2b1286c42f0519ab304fa368498dd4342bb553

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