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.11-cp314-cp314-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.14Windows x86-64

fabricatio_rag-0.1.11-cp314-cp314-manylinux_2_34_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

fabricatio_rag-0.1.11-cp314-cp314-manylinux_2_34_aarch64.whl (2.6 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ ARM64

fabricatio_rag-0.1.11-cp314-cp314-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

fabricatio_rag-0.1.11-cp313-cp313-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.13Windows x86-64

fabricatio_rag-0.1.11-cp313-cp313-manylinux_2_34_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

fabricatio_rag-0.1.11-cp313-cp313-manylinux_2_34_aarch64.whl (2.6 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

fabricatio_rag-0.1.11-cp313-cp313-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

fabricatio_rag-0.1.11-cp312-cp312-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.12Windows x86-64

fabricatio_rag-0.1.11-cp312-cp312-manylinux_2_34_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

fabricatio_rag-0.1.11-cp312-cp312-manylinux_2_34_aarch64.whl (2.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

fabricatio_rag-0.1.11-cp312-cp312-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file fabricatio_rag-0.1.11-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for fabricatio_rag-0.1.11-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 5703fe0622f1e562c2551f1ddf5caf2bb3d2b5d75c41a48467864efd58ecfc1c
MD5 c97b064751039c1551e8678f9c4e7a47
BLAKE2b-256 1d3a24640a93ca5ca061cb7f65bfaaebcd113db2df52221c9cb2d5b2145932be

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.11-cp314-cp314-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for fabricatio_rag-0.1.11-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 a297ec1b760d0d0168c0f1e400234fc217cc7f68715e12ee9df3a30ad322856c
MD5 22962d5c5ac3d7a49b6540961ec7d255
BLAKE2b-256 646223d3a06b51b680900cf43659b631078b0ce8aae4677f02b844a2a6887f43

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.11-cp314-cp314-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for fabricatio_rag-0.1.11-cp314-cp314-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 52189a868c06711d9e7cb45a07c0abea78063f13709f024a93384dbe62f40d3c
MD5 696238690cc60ccf3c62d5fede91d836
BLAKE2b-256 7d8e9123feec917615be7be3b85b1d17ccf12b1c6f325df8bce20545f5cc95d5

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.11-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fabricatio_rag-0.1.11-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b4c81b7f722a1817a7b6cd8d5ca2c04ddf049b617c8fa5cb1e3ad2682cfde3d1
MD5 cbcdc030444605085b0d455d403257f6
BLAKE2b-256 61bdca085b48f35c0e82005904c7942ca15c176d0a65fe7793b5e8703d3f7815

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fabricatio_rag-0.1.11-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 e5391156e891232cb29adaf38d5840545660094eb631cc079bcb30adcaf73f75
MD5 fdf1febb0d3c82e82243d3653d0012c5
BLAKE2b-256 14ce5f976ab76c8ff0db499636c43b57b0c3ac962370f9e73dfa76052919c5ea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fabricatio_rag-0.1.11-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 776314ba2da63b4bd1c782e794be3294b608d046079d318c2cdb372cfb4f1ce3
MD5 17f5c234fbb94a62782e6f7592d06ded
BLAKE2b-256 117d090f6dc3c875c006c38df8832c3e59059b674f7a9c0db22ee49ede3a0bee

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fabricatio_rag-0.1.11-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 a4b4ebcfd74c3699d4fb8baeaeaa66c50e87b046b7067d613aab247715e4540f
MD5 3ab7f2632c9340d888ee53bc72509082
BLAKE2b-256 b0a0e2b1b4882c72656a0567ce7d832c8a650f3219f9941cbe99a7ff40cbf6ae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fabricatio_rag-0.1.11-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 af12eeb54739d810e9e0e28638945a2440e563e415b06f3a2a27ec9667f4e393
MD5 f33e29a5c31c48575cd8fa7e9dd5fe96
BLAKE2b-256 5b7eb6f7510f75a0f4e29ffd503cce20fc13e6398b6e7e5bc89514c68daec8ba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fabricatio_rag-0.1.11-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 f707a28fc3080d021cee7eafaa6a5f6b1ab965ae3f01f883a489a987b3622a51
MD5 f7a500d85b329f7b65aa4ef3ee98d53a
BLAKE2b-256 ff34729e726b1bf82ae25085419d6f507f882209b327aff51c5aed75d6cd96e6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fabricatio_rag-0.1.11-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 b3170217b56dbf15e70a8ac0e5bffceb77f9154f270edba8f1ef1d927123301d
MD5 48bc82d527c18d464df58cff12f5a77d
BLAKE2b-256 d45097a3d77e021898359c7fe438c0aa8229df4e3013ce33258398c40e9cd4a3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fabricatio_rag-0.1.11-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 ff3618d106369d9c93da29f569e1f723bdb0477b15bd846c0d038a4e21e60f5d
MD5 84622d4eddac1a4667052692adccc8b0
BLAKE2b-256 1f4e845a0a4b6103f6d6ba45f17f228abbde6f4ba666f511e10eb197f09cbf43

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fabricatio_rag-0.1.11-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3b1fdb0a098069b7c270fe257066cea8ad84eab06d47f98b88860192cddf9232
MD5 dc2f16287f18d4aca1f5b46efa1dbcd2
BLAKE2b-256 94d4ba5fb1597fde5eb51a5f046f7a72cc4c5d74576ab01c183c5395b2875d8c

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