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

Uploaded CPython 3.13Windows x86-64

fabricatio_rag-0.1.10-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.10-cp313-cp313-manylinux_2_34_aarch64.whl (2.6 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

fabricatio_rag-0.1.10-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.10-cp312-cp312-manylinux_2_34_aarch64.whl (2.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

fabricatio_rag-0.1.10-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.10-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for fabricatio_rag-0.1.10-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 11a34bd2b8bd932e8f9a4c8564fdc79dff88b22a4f5221403eda1aab9df45f05
MD5 63bc594405e9f2f26ed40f3909a90863
BLAKE2b-256 451b2b98ea2168e41bf3e88732ec0239ab71d9e2bde311aef4b4780ef5f97bab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fabricatio_rag-0.1.10-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 965942a44856a98519da5debc1af150b2560fadceea0823313e3aa0bddf21486
MD5 344098b67be62bb9f0314a9fc43ed25c
BLAKE2b-256 2365a479c67f0cc1d2e8443fa8a2b9088c669a89afc70e74769459cc02959ffa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fabricatio_rag-0.1.10-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 3e275aea2103c2db93cd607a055490a0219164ab8447d99ac803c13ef5dd7d50
MD5 63eb9273515d7fa3dcce159835ef0d52
BLAKE2b-256 9069a3675663b72060d312722fcd1a963d628a124ca76f6fae55b386b9f4b0e3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fabricatio_rag-0.1.10-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 88f20c2327cc7f901550e6e79c70ca450280a08d2f8fb6299f788ddcb70283ad
MD5 70a4b819df1b30ad1a839047d6d23016
BLAKE2b-256 b33d480e79b8772e8d3dab1b37c33aebe326dae43ab792f0be085a07045b4b18

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fabricatio_rag-0.1.10-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 f4a81f29c7eeebec88482bc888ab5d29465e0695963621cb76e5a939848fcd6d
MD5 c58c4c80bd7a91815f25de0c00c95e59
BLAKE2b-256 0a3e6292b5dbcb265ab6a272f72a315c67f51ae36e7e95923a66619178323881

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fabricatio_rag-0.1.10-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f6bae8a768ddea250f913490ef9b59fb0051f4d7f0dbb18bb2b7d0add1a169f1
MD5 d2f4f9b46231ea762c4d9bbe13ac083e
BLAKE2b-256 f7c29edd3e50c11252d160a6ffbc315ea06a2d1811c1c051037e53ca7e5fe7ff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fabricatio_rag-0.1.10-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 51b61832fbdb520b5c36e32a17b3a683057f1e2754db12283558c7ef20664aee
MD5 5baf6e11ea7b81468b33b45ade3b2b83
BLAKE2b-256 646c20b433a7df33032ddab45cbf141289ec1367fa94e39cf691aca7f6ca2d83

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fabricatio_rag-0.1.10-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 92afa080138b5ab82ade85bd518e8c9aafa689ce55b07e0690e6c74e6cb94dde
MD5 7d79874f0eed41e1c2c709589f158076
BLAKE2b-256 2478e11642424757c75fcbef4253d276086bfc26fa2fc1cc097216a5c3b896c6

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