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

Uploaded CPython 3.14Windows x86-64

fabricatio_rag-0.1.13.dev2-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.13.dev2-cp314-cp314-manylinux_2_34_aarch64.whl (2.6 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ ARM64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

fabricatio_rag-0.1.13.dev2-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.13.dev2-cp313-cp313-manylinux_2_34_aarch64.whl (2.6 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

fabricatio_rag-0.1.13.dev2-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.13.dev2-cp312-cp312-manylinux_2_34_aarch64.whl (2.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

fabricatio_rag-0.1.13.dev2-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.13.dev2-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: fabricatio_rag-0.1.13.dev2-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 2.5 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.dev2-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 f260a03b67510648ecc92a253888c7aa1747f0be86f469884f2899df204bd6df
MD5 384bd386547e92af0ab06876e63d1ea8
BLAKE2b-256 83467ad26937b7fd55bc2c816a9a9faab906b3d4a0e17dfb75cacbc66c0a0854

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fabricatio_rag-0.1.13.dev2-cp314-cp314-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 2.9 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.dev2-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e98e03ee1a5fd28b3ed632364864e07375cca335cec947c2665aee683fed3619
MD5 b36c685349da1b394350603e3c9cd9da
BLAKE2b-256 0fb757c767c5e9ddedcb71c16121c7cc1ba2826ff95a0aa3b676d98dd0655295

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fabricatio_rag-0.1.13.dev2-cp314-cp314-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 2.6 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.dev2-cp314-cp314-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 be81f1c9cde216cd9b0ec46b648d9406309a0ce9f0d0043b86be430f7abd99b0
MD5 16daf25d779ee473aa6a03ee2d7e0dcf
BLAKE2b-256 4d9fced330911af7def3b578de702b93abcbd791cb250da3a64980f41449eb8c

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.13.dev2-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

  • Download URL: fabricatio_rag-0.1.13.dev2-cp314-cp314-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 2.6 MB
  • Tags: CPython 3.14, macOS 11.0+ 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":"macOS","version":null,"id":null,"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.dev2-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 161733cf53ae017ac6d73e34fe8b69ed3b35314a16221bb6e2cd5ab455c90ea7
MD5 2d17e9e51640c1c17b84e2b8e7fd230f
BLAKE2b-256 b385d86a8f99dd5cb064d0e1d46006d93c5e00f6a0af650da9f8379e377311e8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fabricatio_rag-0.1.13.dev2-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 2.5 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.dev2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 08b68022f30b2013f456ba0bc474584cd83c0ba2a70d60690a1964cf22a22285
MD5 30c5f6af84e5051e1b1f5e1cd51a295d
BLAKE2b-256 c19de9a38c425f34bb5b95fa56cb59ce362b142b1785e4206d97636dfd1210be

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fabricatio_rag-0.1.13.dev2-cp313-cp313-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 2.9 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.dev2-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 26cede48caf072edf3c4f939bf7a93e7a98e969bfd541b06dc58b1bafbe8ab8a
MD5 127f130a88a87859905af2624db37da2
BLAKE2b-256 bac9b0d99286793ba556bf0c4f9d690bfb811f9f1fc7fa9a15782746d7103949

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fabricatio_rag-0.1.13.dev2-cp313-cp313-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 2.6 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.dev2-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 5c3425abc91e85644fcc6e13fe777cf1ab02df38dcafdf2925d82080c8a03067
MD5 f91c55c90196c712dc196ceb6dca23f8
BLAKE2b-256 4a042d3557f09698cd2bd5f55ff2cd4fc937ef09ed22f158504fba1aa219c249

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.13.dev2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

  • Download URL: fabricatio_rag-0.1.13.dev2-cp313-cp313-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 2.6 MB
  • Tags: CPython 3.13, macOS 11.0+ 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":"macOS","version":null,"id":null,"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.dev2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ecaf73008baaab83add4e5c30238a98ff6394a6aa32e3a99cb86c4778e885211
MD5 42256d6c487b0af0221231a11c887843
BLAKE2b-256 460e5d982231745bf5255c62d14acd91902ea80fe58dc3390c4f91e3d3c51d8c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fabricatio_rag-0.1.13.dev2-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 2.5 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.dev2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 cc43d85af7d42ca25b41c122281288772ab8ab0992d1f30ebc2d59a14d699a54
MD5 c86c4d9b7683029871259d01ad3c89d6
BLAKE2b-256 b8907d89be505504e28506434d9376a26736874cdda0000e057d096db4bceb67

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fabricatio_rag-0.1.13.dev2-cp312-cp312-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 2.9 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.dev2-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 11cccbff5123f3701db2fcef36fb6fdcc6a01a5e4d4e73b57a9b4c18c4dd1171
MD5 86cc68cbd1ec1e69129f1c80278ded26
BLAKE2b-256 5f473fdf8bdf0563a105db7db34a1badb47a2eb9301d29e96c7e639e2055863d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fabricatio_rag-0.1.13.dev2-cp312-cp312-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 2.6 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.dev2-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 c5dd09052af479e01d2aac04646d7094bf76ba66075eb54cbda7667291857401
MD5 8c1e924be550b2e59364c270a00188ca
BLAKE2b-256 540a9715e172583bb9d383a6a3b638d1e36414b63312b83a846952bf88bba98c

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.13.dev2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

  • Download URL: fabricatio_rag-0.1.13.dev2-cp312-cp312-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 2.6 MB
  • Tags: CPython 3.12, macOS 11.0+ 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":"macOS","version":null,"id":null,"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.dev2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b01e6de7216d6ecc2f158c307fe1c114647802075c5591715b6136fd0a9c3963
MD5 262b626f3f9a5bbfa3d3ea69d46e2cbe
BLAKE2b-256 66ff5f9cdda98347d001b74e6e17dbcbfacd329ab120329b89dd26a81db49ded

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