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 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

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.13.dev0-cp314-cp314-win_amd64.whl (2.7 MB view details)

Uploaded CPython 3.14Windows x86-64

fabricatio_rag-0.1.13.dev0-cp314-cp314-manylinux_2_34_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

fabricatio_rag-0.1.13.dev0-cp314-cp314-manylinux_2_34_aarch64.whl (2.8 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ ARM64

fabricatio_rag-0.1.13.dev0-cp313-cp313-win_amd64.whl (2.7 MB view details)

Uploaded CPython 3.13Windows x86-64

fabricatio_rag-0.1.13.dev0-cp313-cp313-manylinux_2_34_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

fabricatio_rag-0.1.13.dev0-cp313-cp313-manylinux_2_34_aarch64.whl (2.8 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

fabricatio_rag-0.1.13.dev0-cp312-cp312-win_amd64.whl (2.7 MB view details)

Uploaded CPython 3.12Windows x86-64

fabricatio_rag-0.1.13.dev0-cp312-cp312-manylinux_2_34_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

fabricatio_rag-0.1.13.dev0-cp312-cp312-manylinux_2_34_aarch64.whl (2.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

File details

Details for the file fabricatio_rag-0.1.13.dev0-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: fabricatio_rag-0.1.13.dev0-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 2.7 MB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":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.1.13.dev0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 7a1fbd2b2689acbfe2c17b409bcab739367751c827c8fb44941442eaa33cdaaf
MD5 069dd6bf22f6a7d74e8997243c991063
BLAKE2b-256 3d198ab002cd2994722b8ba37f3b15b7eeae54507e571bb8fc29053d15f346b1

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.13.dev0-cp314-cp314-manylinux_2_34_x86_64.whl.

File metadata

  • Download URL: fabricatio_rag-0.1.13.dev0-cp314-cp314-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 3.2 MB
  • Tags: CPython 3.14, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","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.1.13.dev0-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 4bd771131bbb0ea1b93e7a334f69d8e1c5d4275f182580d33323fa4eb16ac6d6
MD5 f463fde93f804c532eacd483657e0cb6
BLAKE2b-256 f77ed9bd31b90cc4d47d3a36097974fe02d878fd226501e1183a4e5375c1a641

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.13.dev0-cp314-cp314-manylinux_2_34_aarch64.whl.

File metadata

  • Download URL: fabricatio_rag-0.1.13.dev0-cp314-cp314-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: CPython 3.14, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","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.1.13.dev0-cp314-cp314-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 cd028e7e78ebb7c79e414de8e32dc07f1b93d3406284acfe2fbe8ae1cae5608e
MD5 1085088581808ea64d6f457ad998ad2e
BLAKE2b-256 aa8a71eb5189b5e1c445d86a2c796af56823d55506ccd59bda3f87b24545db96

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.13.dev0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: fabricatio_rag-0.1.13.dev0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 2.7 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":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.1.13.dev0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 e884645438f07619d75343607f56338c8cf641ca8a4d8e1cd3b35c31ea57b9ac
MD5 c66eeb2c3b3932e0f5d4d52602b149ea
BLAKE2b-256 d32c83cb3ffd905626b213d37ebfd8c5e30ca0176b84b479315658be8eed485d

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.13.dev0-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

  • Download URL: fabricatio_rag-0.1.13.dev0-cp313-cp313-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 3.2 MB
  • Tags: CPython 3.13, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","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.1.13.dev0-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 8e6563fa3e097cfd711cf314531314d1f8cc0c643787e4e5258fc9bd1e1e959a
MD5 e44d7e0e25274e21145b1059006d207f
BLAKE2b-256 f8fe06505028250ca00fcb78fe16640906b85739d308c3f5ca3646cbcb388ed6

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.13.dev0-cp313-cp313-manylinux_2_34_aarch64.whl.

File metadata

  • Download URL: fabricatio_rag-0.1.13.dev0-cp313-cp313-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: CPython 3.13, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","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.1.13.dev0-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 30f4ccc4dd1dfa42cb3a94db360a8050ffb775d0380f2ece0a00fe30446aace7
MD5 ff703fbcd4f98f32f08376f658709aa6
BLAKE2b-256 266a643aa8e73ff074484f10d54f387efba846e828167b1f20d343e6ef5ec7f2

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.13.dev0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: fabricatio_rag-0.1.13.dev0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 2.7 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":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.1.13.dev0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 805d39b68926974cb5c19b895dc6d56a5d540c147a1323618185f29ee39cec3c
MD5 d99102a5bc7654563513c5c7bd444a2e
BLAKE2b-256 2d6110284e88c2d774dd20cf33214e4d996366f7bada338195620b91021230da

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.13.dev0-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

  • Download URL: fabricatio_rag-0.1.13.dev0-cp312-cp312-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 3.2 MB
  • Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","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.1.13.dev0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 5c75491c59e7f7b877ad21f58937ad9ee4bf9aab598ccdccc90ae5d0178625aa
MD5 af9e626782292184927f9ab3cd511b10
BLAKE2b-256 81ff2773fa134d02ad515cea6756885db993198805e137ceffa8eef794fd2465

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.13.dev0-cp312-cp312-manylinux_2_34_aarch64.whl.

File metadata

  • Download URL: fabricatio_rag-0.1.13.dev0-cp312-cp312-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: CPython 3.12, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","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.1.13.dev0-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 5e2b579178a5cec10c84713627bd2be24ac14a437c03288bd1e80f9db031c426
MD5 32ce82596d21a5873f0e4720836932d2
BLAKE2b-256 ee69e50a5a8a3deb475c74d8e8b6ed3307781b5e643097e351aa12580590be0d

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