maktaba 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. maktaba-0.1.0/.env.example +30 -0
  2. maktaba-0.1.0/.github/workflows/ci.yml +51 -0
  3. maktaba-0.1.0/.github/workflows/publish.yml +74 -0
  4. maktaba-0.1.0/.github/workflows/test-build.yml +42 -0
  5. maktaba-0.1.0/.gitignore +54 -0
  6. maktaba-0.1.0/.python-version +1 -0
  7. maktaba-0.1.0/CHANGELOG.md +33 -0
  8. maktaba-0.1.0/LICENSE +21 -0
  9. maktaba-0.1.0/PKG-INFO +157 -0
  10. maktaba-0.1.0/README.md +96 -0
  11. maktaba-0.1.0/docs/Examples.md +9 -0
  12. maktaba-0.1.0/docs/Overview.md +9 -0
  13. maktaba-0.1.0/docs/Pipelines.md +13 -0
  14. maktaba-0.1.0/docs/Providers.md +12 -0
  15. maktaba-0.1.0/docs/Quickstart.md +35 -0
  16. maktaba-0.1.0/docs/Troubleshooting.md +15 -0
  17. maktaba-0.1.0/examples/advanced_query_pipeline.py +46 -0
  18. maktaba-0.1.0/examples/basic_usage.py +142 -0
  19. maktaba-0.1.0/examples/chunking_example.py +126 -0
  20. maktaba-0.1.0/examples/custom_embedder.py +45 -0
  21. maktaba-0.1.0/examples/custom_provider.py +0 -0
  22. maktaba-0.1.0/examples/ingestion_pipeline.py +73 -0
  23. maktaba-0.1.0/examples/kutub_integration.py +0 -0
  24. maktaba-0.1.0/examples/query_pipeline.py +44 -0
  25. maktaba-0.1.0/pyproject.toml +112 -0
  26. maktaba-0.1.0/src/maktaba/__init__.py +42 -0
  27. maktaba-0.1.0/src/maktaba/chunking/__init__.py +12 -0
  28. maktaba-0.1.0/src/maktaba/chunking/base.py +83 -0
  29. maktaba-0.1.0/src/maktaba/chunking/llamaindex.py +0 -0
  30. maktaba-0.1.0/src/maktaba/chunking/models.py +72 -0
  31. maktaba-0.1.0/src/maktaba/chunking/simple.py +0 -0
  32. maktaba-0.1.0/src/maktaba/chunking/unstructured.py +343 -0
  33. maktaba-0.1.0/src/maktaba/citation/__init__.py +0 -0
  34. maktaba-0.1.0/src/maktaba/citation/formatter.py +37 -0
  35. maktaba-0.1.0/src/maktaba/config.py +0 -0
  36. maktaba-0.1.0/src/maktaba/embedding/__init__.py +9 -0
  37. maktaba-0.1.0/src/maktaba/embedding/azure.py +0 -0
  38. maktaba-0.1.0/src/maktaba/embedding/base.py +72 -0
  39. maktaba-0.1.0/src/maktaba/embedding/cohere.py +0 -0
  40. maktaba-0.1.0/src/maktaba/embedding/openai.py +111 -0
  41. maktaba-0.1.0/src/maktaba/embedding/voyage.py +0 -0
  42. maktaba-0.1.0/src/maktaba/exceptions.py +37 -0
  43. maktaba-0.1.0/src/maktaba/logging.py +25 -0
  44. maktaba-0.1.0/src/maktaba/models.py +146 -0
  45. maktaba-0.1.0/src/maktaba/pipeline/__init__.py +0 -0
  46. maktaba-0.1.0/src/maktaba/pipeline/ingestion.py +169 -0
  47. maktaba-0.1.0/src/maktaba/pipeline/query.py +131 -0
  48. maktaba-0.1.0/src/maktaba/reranking/__init__.py +0 -0
  49. maktaba-0.1.0/src/maktaba/reranking/base.py +34 -0
  50. maktaba-0.1.0/src/maktaba/reranking/cohere.py +87 -0
  51. maktaba-0.1.0/src/maktaba/reranking/cross_encoder.py +0 -0
  52. maktaba-0.1.0/src/maktaba/retrieval/__init__.py +0 -0
  53. maktaba-0.1.0/src/maktaba/retrieval/hybrid.py +0 -0
  54. maktaba-0.1.0/src/maktaba/retrieval/query_condenser.py +228 -0
  55. maktaba-0.1.0/src/maktaba/retrieval/vector.py +0 -0
  56. maktaba-0.1.0/src/maktaba/storage/__init__.py +9 -0
  57. maktaba-0.1.0/src/maktaba/storage/base.py +137 -0
  58. maktaba-0.1.0/src/maktaba/storage/chroma.py +119 -0
  59. maktaba-0.1.0/src/maktaba/storage/pinecone.py +124 -0
  60. maktaba-0.1.0/src/maktaba/storage/qdrant.py +439 -0
  61. maktaba-0.1.0/src/maktaba/storage/weaviate.py +133 -0
  62. maktaba-0.1.0/src/maktaba/version.py +0 -0
  63. maktaba-0.1.0/tests/__init__.py +0 -0
  64. maktaba-0.1.0/tests/conftest.py +0 -0
  65. maktaba-0.1.0/tests/test_chunking.py +0 -0
  66. maktaba-0.1.0/tests/test_embedding.py +0 -0
  67. maktaba-0.1.0/tests/test_ingestion.py +114 -0
  68. maktaba-0.1.0/tests/test_pipeline.py +58 -0
  69. maktaba-0.1.0/tests/test_reranking.py +18 -0
  70. maktaba-0.1.0/tests/test_retrieval.py +0 -0
  71. maktaba-0.1.0/tests/test_storage.py +0 -0
  72. maktaba-0.1.0/uv.lock +6737 -0
@@ -0,0 +1,30 @@
1
+ # Maktaba environment variables (copy to .env and edit values)
2
+
3
+ # OpenAI embeddings (required for examples using OpenAIEmbedder)
4
+ OPENAI_API_KEY=sk-your-openai-key
5
+
6
+ # Qdrant connection
7
+ # Use ":memory:" for in-memory testing (no server required)
8
+ # Or set to your server, e.g., "http://localhost:6333" or Qdrant Cloud URL
9
+ QDRANT_URL=:memory:
10
+
11
+ # Optional: Qdrant API key (for Qdrant Cloud)
12
+ QDRANT_API_KEY=
13
+
14
+ # Cohere Reranker (optional). If set, examples can enable API reranking.
15
+ COHERE_API_KEY=
16
+
17
+ # Logging level for pipelines (DEBUG, INFO, WARNING, ERROR)
18
+ MAKTABA_LOG_LEVEL=INFO
19
+
20
+ # Pinecone (optional)
21
+ PINECONE_API_KEY=
22
+ PINECONE_INDEX=
23
+
24
+ # Chroma (optional)
25
+ # If set, Chroma will persist data to this directory; otherwise in-memory
26
+ CHROMA_PERSIST_DIR=
27
+
28
+ # Weaviate (optional)
29
+ WEAVIATE_URL=
30
+ WEAVIATE_API_KEY=
@@ -0,0 +1,51 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ main, master ]
6
+ pull_request:
7
+ branches: [ main, master ]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ python-version: ["3.10", "3.12"]
15
+
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+ - name: Set up Python
19
+ uses: actions/setup-python@v5
20
+ with:
21
+ python-version: ${{ matrix.python-version }}
22
+
23
+ - name: Install uv
24
+ run: |
25
+ pip install uv
26
+
27
+ - name: Sync dependencies
28
+ run: |
29
+ uv sync --dev --all-extras
30
+
31
+ - name: Lint with ruff
32
+ run: |
33
+ uv run ruff check .
34
+
35
+ - name: Type check with mypy
36
+ run: |
37
+ uv run mypy src/maktaba --no-error-summary 2>&1 | tee mypy.log || true
38
+ ERROR_COUNT=$(grep -c "error:" mypy.log || echo 0)
39
+ echo "MyPy found $ERROR_COUNT errors"
40
+ # Fail if errors exceed threshold (allow third-party type stub issues)
41
+ if [ "$ERROR_COUNT" -gt 20 ]; then
42
+ echo "Too many type errors (threshold: 20)"
43
+ exit 1
44
+ fi
45
+
46
+ - name: Run tests
47
+ env:
48
+ PYTHONPATH: src
49
+ run: |
50
+ uv run pytest -q
51
+
@@ -0,0 +1,74 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ permissions:
8
+ contents: read
9
+ id-token: write # Required for trusted publishing
10
+
11
+ jobs:
12
+ build:
13
+ name: Build distribution
14
+ runs-on: ubuntu-latest
15
+
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - name: Set up Python
20
+ uses: actions/setup-python@v5
21
+ with:
22
+ python-version: "3.12"
23
+
24
+ - name: Install uv
25
+ run: |
26
+ pip install uv
27
+
28
+ - name: Build package
29
+ run: |
30
+ uv build
31
+
32
+ - name: Store distribution packages
33
+ uses: actions/upload-artifact@v4
34
+ with:
35
+ name: python-package-distributions
36
+ path: dist/
37
+
38
+ publish-to-pypi:
39
+ name: Publish to PyPI
40
+ needs: build
41
+ runs-on: ubuntu-latest
42
+ environment:
43
+ name: pypi
44
+ url: https://pypi.org/p/maktaba
45
+
46
+ steps:
47
+ - name: Download distributions
48
+ uses: actions/download-artifact@v4
49
+ with:
50
+ name: python-package-distributions
51
+ path: dist/
52
+
53
+ - name: Publish to PyPI
54
+ uses: pypa/gh-action-pypi-publish@release/v1
55
+
56
+ publish-to-testpypi:
57
+ name: Publish to TestPyPI
58
+ needs: build
59
+ runs-on: ubuntu-latest
60
+ environment:
61
+ name: testpypi
62
+ url: https://test.pypi.org/p/maktaba
63
+
64
+ steps:
65
+ - name: Download distributions
66
+ uses: actions/download-artifact@v4
67
+ with:
68
+ name: python-package-distributions
69
+ path: dist/
70
+
71
+ - name: Publish to TestPyPI
72
+ uses: pypa/gh-action-pypi-publish@release/v1
73
+ with:
74
+ repository-url: https://test.pypi.org/legacy/
@@ -0,0 +1,42 @@
1
+ name: Test Build
2
+
3
+ on:
4
+ pull_request:
5
+ branches: [ main, master ]
6
+ push:
7
+ branches: [ main, master ]
8
+
9
+ jobs:
10
+ build:
11
+ name: Verify package builds
12
+ runs-on: ubuntu-latest
13
+
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+
17
+ - name: Set up Python
18
+ uses: actions/setup-python@v5
19
+ with:
20
+ python-version: "3.12"
21
+
22
+ - name: Install uv
23
+ run: |
24
+ pip install uv
25
+
26
+ - name: Build package
27
+ run: |
28
+ uv build
29
+
30
+ - name: Check build artifacts
31
+ run: |
32
+ ls -lh dist/
33
+ echo "Build artifacts created successfully"
34
+
35
+ - name: Install from wheel
36
+ run: |
37
+ python -m venv .test-venv
38
+ .test-venv/bin/pip install dist/*.whl
39
+
40
+ - name: Test import
41
+ run: |
42
+ .test-venv/bin/python -c "import maktaba; print(f'Successfully imported maktaba {maktaba.__version__}')"
@@ -0,0 +1,54 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ build/
8
+ develop-eggs/
9
+ dist/
10
+ downloads/
11
+ eggs/
12
+ .eggs/
13
+ lib/
14
+ lib64/
15
+ parts/
16
+ sdist/
17
+ var/
18
+ wheels/
19
+ *.egg-info/
20
+ .installed.cfg
21
+ *.egg
22
+
23
+ # Virtual environments
24
+ venv/
25
+ env/
26
+ ENV/
27
+ .venv
28
+
29
+ # IDEs
30
+ .vscode/
31
+ .idea/
32
+ *.swp
33
+ *.swo
34
+ *~
35
+
36
+ # Testing
37
+ .pytest_cache/
38
+ .coverage
39
+ htmlcov/
40
+ .tox/
41
+
42
+ # Type checking
43
+ .mypy_cache/
44
+ .dmypy.json
45
+ dmypy.json
46
+
47
+ # Environment
48
+ .env
49
+ .env.local
50
+ *.env
51
+
52
+ # OS
53
+ .DS_Store
54
+ Thumbs.db
@@ -0,0 +1 @@
1
+ 3.12
@@ -0,0 +1,33 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ### Added
11
+ - Initial project setup
12
+
13
+ ## [0.1.0] - YYYY-MM-DD
14
+
15
+ ### Added
16
+ - Query pipeline with automatic reranking and citation formatting
17
+ - Ingestion pipeline for document processing
18
+ - Provider-agnostic embedding support (OpenAI, Azure, Cohere, Voyage)
19
+ - Vector store integrations (Qdrant, Pinecone, Chroma, Redis)
20
+ - Unstructured document chunking via LlamaIndex
21
+ - Cohere reranking support
22
+ - Async-first API design
23
+ - Full type hints and Pydantic validation
24
+ - Comprehensive test coverage
25
+ - Arabic and multilingual language support
26
+
27
+ ### Documentation
28
+ - Overview, quickstart, and provider guides
29
+ - Example scripts for common use cases
30
+ - API reference documentation
31
+
32
+ [Unreleased]: https://github.com/nuhatech/maktaba/compare/v0.1.0...HEAD
33
+ [0.1.0]: https://github.com/nuhatech/maktaba/releases/tag/v0.1.0
maktaba-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 NuhaTech
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
maktaba-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,157 @@
1
+ Metadata-Version: 2.4
2
+ Name: maktaba
3
+ Version: 0.1.0
4
+ Summary: Production-ready RAG infrastructure for Arabic & multilingual applications
5
+ Project-URL: Homepage, https://github.com/nuhatech/maktaba
6
+ Project-URL: Documentation, https://maktaba.nuhatech.com
7
+ Project-URL: Repository, https://github.com/nuhatech/maktaba
8
+ Project-URL: Issues, https://github.com/nuhatech/maktaba/issues
9
+ Author-email: NuhaTech <contact@nuhatech.com>
10
+ License: MIT
11
+ License-File: LICENSE
12
+ Keywords: ai,embeddings,llm,rag,retrieval,vector-search
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Requires-Python: >=3.10
21
+ Requires-Dist: httpx>=0.27
22
+ Requires-Dist: pydantic-settings>=2.0
23
+ Requires-Dist: pydantic>=2.0
24
+ Requires-Dist: tenacity>=8.0
25
+ Provides-Extra: all
26
+ Requires-Dist: azure-ai-inference>=1.0.0b9; extra == 'all'
27
+ Requires-Dist: chromadb>=0.4; extra == 'all'
28
+ Requires-Dist: cohere>=5.0; extra == 'all'
29
+ Requires-Dist: llama-index-core>=0.12; extra == 'all'
30
+ Requires-Dist: llama-index-readers-file>=0.4; extra == 'all'
31
+ Requires-Dist: openai>=1.0; extra == 'all'
32
+ Requires-Dist: pinecone-client>=3.0; extra == 'all'
33
+ Requires-Dist: python-magic>=0.4; extra == 'all'
34
+ Requires-Dist: qdrant-client>=1.11; extra == 'all'
35
+ Requires-Dist: redis>=5.0; extra == 'all'
36
+ Requires-Dist: unstructured[all-docs]>=0.16; extra == 'all'
37
+ Requires-Dist: voyageai>=0.2; extra == 'all'
38
+ Provides-Extra: azure
39
+ Requires-Dist: azure-ai-inference>=1.0.0b9; extra == 'azure'
40
+ Provides-Extra: chroma
41
+ Requires-Dist: chromadb>=0.4; extra == 'chroma'
42
+ Provides-Extra: cohere
43
+ Requires-Dist: cohere>=5.0; extra == 'cohere'
44
+ Provides-Extra: openai
45
+ Requires-Dist: openai>=1.0; extra == 'openai'
46
+ Provides-Extra: pinecone
47
+ Requires-Dist: pinecone-client>=3.0; extra == 'pinecone'
48
+ Provides-Extra: qdrant
49
+ Requires-Dist: qdrant-client>=1.11; extra == 'qdrant'
50
+ Provides-Extra: redis
51
+ Requires-Dist: redis>=5.0; extra == 'redis'
52
+ Provides-Extra: unstructured
53
+ Requires-Dist: llama-index-core>=0.12; extra == 'unstructured'
54
+ Requires-Dist: llama-index-readers-file>=0.4; extra == 'unstructured'
55
+ Requires-Dist: python-magic-bin>=0.4; (platform_system == 'Windows') and extra == 'unstructured'
56
+ Requires-Dist: python-magic>=0.4; (platform_system != 'Windows') and extra == 'unstructured'
57
+ Requires-Dist: unstructured[all-docs]>=0.16; extra == 'unstructured'
58
+ Provides-Extra: voyage
59
+ Requires-Dist: voyageai>=0.2; extra == 'voyage'
60
+ Description-Content-Type: text/markdown
61
+
62
+ # Maktaba
63
+
64
+ [![CI](https://github.com/nuhatech/maktaba/actions/workflows/ci.yml/badge.svg)](https://github.com/nuhatech/maktaba/actions/workflows/ci.yml)
65
+ [![PyPI version](https://badge.fury.io/py/maktaba.svg)](https://badge.fury.io/py/maktaba)
66
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
67
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
68
+
69
+ **The library for building libraries** - By NuhaTech
70
+
71
+ > From the Arabic word for library, Maktaba is a modern RAG infrastructure for building intelligent knowledge systems in any language.
72
+
73
+ ## Features
74
+
75
+ - 🔌 **Provider-agnostic**: Works with OpenAI, Cohere, Azure, and more
76
+ - 🚀 **Production-ready**: Built for scale with async-first design
77
+ - 🧩 **Modular**: Use only what you need
78
+ - 🌍 **Multilingual**: Optimized for Arabic and international languages
79
+ - 📊 **Type-safe**: Full type hints and Pydantic validation
80
+ - 🧪 **Well-tested**: Comprehensive test coverage
81
+
82
+ ## Installation
83
+
84
+ ### Using UV (Recommended)
85
+
86
+ ```bash
87
+ # Install UV if you haven't already
88
+ curl -LsSf https://astral.sh/uv/install.sh | sh
89
+
90
+ # Add maktaba to your project
91
+ uv add maktaba
92
+
93
+ # With OpenAI + Qdrant
94
+ uv add "maktaba[openai,qdrant]"
95
+
96
+ # With all providers
97
+ uv add "maktaba[all]"
98
+ ```
99
+
100
+ ### Using pip
101
+
102
+ ```bash
103
+ # Basic installation
104
+ pip install maktaba
105
+
106
+ # With OpenAI + Qdrant
107
+ pip install "maktaba[openai,qdrant]"
108
+
109
+ # With all providers
110
+ pip install "maktaba[all]"
111
+ ```
112
+
113
+ ## Quick Start
114
+
115
+ ```python
116
+ from maktaba.pipeline import QueryPipeline
117
+ from maktaba.embedding import OpenAIEmbedder
118
+ from maktaba.storage import QdrantStore
119
+ from maktaba.reranking import CohereReranker
120
+
121
+ # Create pipeline
122
+ pipeline = QueryPipeline(
123
+ embedder=OpenAIEmbedder(api_key="..."),
124
+ vector_store=QdrantStore(url="http://localhost:6333", collection_name="docs"),
125
+ reranker=CohereReranker(api_key="...")
126
+ )
127
+
128
+ # Search with automatic reranking and citation formatting
129
+ result = await pipeline.search(
130
+ query="What is Tawhid?",
131
+ top_k=10,
132
+ rerank=True
133
+ )
134
+
135
+ # Use in your LLM prompt
136
+ print(result["formatted_context"]) # [1]: content... [2]: content...
137
+ print(result["citations"]) # [{id: 1, source: "...", score: 0.95}, ...]
138
+ ```
139
+
140
+ ## Documentation
141
+
142
+ - Overview: docs/Overview.md
143
+ - Quickstart: docs/Quickstart.md
144
+ - Pipelines: docs/Pipelines.md
145
+ - Providers: docs/Providers.md
146
+ - Examples: docs/Examples.md
147
+ - Troubleshooting: docs/Troubleshooting.md
148
+
149
+ Website (coming soon): maktaba.nuhatech.com
150
+
151
+ ## License
152
+
153
+ MIT License - see [LICENSE](LICENSE)
154
+
155
+ ## About NuhaTech
156
+
157
+ Built by [NuhaTech](https://nuhatech.com) - creators of Kutub and Muqabia.
@@ -0,0 +1,96 @@
1
+ # Maktaba
2
+
3
+ [![CI](https://github.com/nuhatech/maktaba/actions/workflows/ci.yml/badge.svg)](https://github.com/nuhatech/maktaba/actions/workflows/ci.yml)
4
+ [![PyPI version](https://badge.fury.io/py/maktaba.svg)](https://badge.fury.io/py/maktaba)
5
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ **The library for building libraries** - By NuhaTech
9
+
10
+ > From the Arabic word for library, Maktaba is a modern RAG infrastructure for building intelligent knowledge systems in any language.
11
+
12
+ ## Features
13
+
14
+ - 🔌 **Provider-agnostic**: Works with OpenAI, Cohere, Azure, and more
15
+ - 🚀 **Production-ready**: Built for scale with async-first design
16
+ - 🧩 **Modular**: Use only what you need
17
+ - 🌍 **Multilingual**: Optimized for Arabic and international languages
18
+ - 📊 **Type-safe**: Full type hints and Pydantic validation
19
+ - 🧪 **Well-tested**: Comprehensive test coverage
20
+
21
+ ## Installation
22
+
23
+ ### Using UV (Recommended)
24
+
25
+ ```bash
26
+ # Install UV if you haven't already
27
+ curl -LsSf https://astral.sh/uv/install.sh | sh
28
+
29
+ # Add maktaba to your project
30
+ uv add maktaba
31
+
32
+ # With OpenAI + Qdrant
33
+ uv add "maktaba[openai,qdrant]"
34
+
35
+ # With all providers
36
+ uv add "maktaba[all]"
37
+ ```
38
+
39
+ ### Using pip
40
+
41
+ ```bash
42
+ # Basic installation
43
+ pip install maktaba
44
+
45
+ # With OpenAI + Qdrant
46
+ pip install "maktaba[openai,qdrant]"
47
+
48
+ # With all providers
49
+ pip install "maktaba[all]"
50
+ ```
51
+
52
+ ## Quick Start
53
+
54
+ ```python
55
+ from maktaba.pipeline import QueryPipeline
56
+ from maktaba.embedding import OpenAIEmbedder
57
+ from maktaba.storage import QdrantStore
58
+ from maktaba.reranking import CohereReranker
59
+
60
+ # Create pipeline
61
+ pipeline = QueryPipeline(
62
+ embedder=OpenAIEmbedder(api_key="..."),
63
+ vector_store=QdrantStore(url="http://localhost:6333", collection_name="docs"),
64
+ reranker=CohereReranker(api_key="...")
65
+ )
66
+
67
+ # Search with automatic reranking and citation formatting
68
+ result = await pipeline.search(
69
+ query="What is Tawhid?",
70
+ top_k=10,
71
+ rerank=True
72
+ )
73
+
74
+ # Use in your LLM prompt
75
+ print(result["formatted_context"]) # [1]: content... [2]: content...
76
+ print(result["citations"]) # [{id: 1, source: "...", score: 0.95}, ...]
77
+ ```
78
+
79
+ ## Documentation
80
+
81
+ - Overview: docs/Overview.md
82
+ - Quickstart: docs/Quickstart.md
83
+ - Pipelines: docs/Pipelines.md
84
+ - Providers: docs/Providers.md
85
+ - Examples: docs/Examples.md
86
+ - Troubleshooting: docs/Troubleshooting.md
87
+
88
+ Website (coming soon): maktaba.nuhatech.com
89
+
90
+ ## License
91
+
92
+ MIT License - see [LICENSE](LICENSE)
93
+
94
+ ## About NuhaTech
95
+
96
+ Built by [NuhaTech](https://nuhatech.com) - creators of Kutub and Muqabia.
@@ -0,0 +1,9 @@
1
+ % Examples
2
+
3
+ - `examples/basic_usage.py` — embeddings + vector search
4
+ - `examples/query_pipeline.py` — QueryPipeline with reranking + citations
5
+ - `examples/ingestion_pipeline.py` — IngestionPipeline + QueryPipeline
6
+
7
+ Tips
8
+ - Set `OPENAI_API_KEY` to run OpenAI embedder
9
+ - Use `url=":memory:"` for Qdrant in-memory testing
@@ -0,0 +1,9 @@
1
+ % Maktaba Overview
2
+
3
+ Maktaba is a production‑ready RAG library for Arabic & multilingual applications.
4
+
5
+ - Vector store–friendly API (camelCase params, namespaces)
6
+ - Embedding providers with batch‑first, async interfaces
7
+ - Document chunking via Unstructured/LlamaIndex
8
+ - QueryPipeline: retrieve → optional rerank → citations
9
+ - IngestionPipeline: chunk → embed → upsert
@@ -0,0 +1,13 @@
1
+ % Pipelines
2
+
3
+ QueryPipeline
4
+ - Embeds the query (input_type="query")
5
+ - Retrieves from store (camelCase: topK, includeMetadata, namespace)
6
+ - Optional rerank step (e.g., CohereReranker)
7
+ - Formats citations into `[n]:` blocks
8
+
9
+ IngestionPipeline
10
+ - Chunk (text/file/url) via a BaseChunker (UnstructuredChunker)
11
+ - Embed chunks in batches (input_type="document")
12
+ - Upsert as `{doc_id}#chunk_{i}` ids
13
+ - Optional on_progress callback
@@ -0,0 +1,12 @@
1
+ % Providers
2
+
3
+ Embedders
4
+ - OpenAI (implemented): `maktaba.embedding.openai.OpenAIEmbedder`
5
+ - Others can be added by subclassing `BaseEmbedder`
6
+
7
+ Vector Stores
8
+ - Qdrant (implemented): `maktaba.storage.qdrant.QdrantStore`
9
+ - Pinecone/Weaviate/Chroma stubs exist; interface follows BaseVectorStore
10
+
11
+ Rerankers
12
+ - CohereReranker with offline heuristic by default
@@ -0,0 +1,35 @@
1
+ % Quickstart
2
+
3
+ Install with UV:
4
+
5
+ ```bash
6
+ cd maktaba
7
+ uv sync --extra openai --extra qdrant
8
+ ```
9
+
10
+ Basic usage:
11
+
12
+ ```python
13
+ from maktaba.embedding import OpenAIEmbedder
14
+ from maktaba.storage import QdrantStore
15
+ from maktaba.models import VectorChunk
16
+
17
+ embedder = OpenAIEmbedder(api_key="sk-...", model="text-embedding-3-large")
18
+ store = QdrantStore(url=":memory:", collection_name="demo")
19
+ store.create_collection(dimension=embedder.dimension)
20
+
21
+ vectors = await embedder.embed_batch(["hello", "world"], input_type="document")
22
+ chunks = [VectorChunk(id=f"doc#chunk_{i}", vector=vectors[i], metadata={"text": t}) for i, t in enumerate(["hello","world"])]
23
+ await store.upsert(chunks)
24
+ ```
25
+
26
+ Query pipeline:
27
+
28
+ ```python
29
+ from maktaba.pipeline.query import QueryPipeline
30
+ from maktaba.reranking.cohere import CohereReranker
31
+
32
+ pipeline = QueryPipeline(embedder, store, reranker=CohereReranker(use_api=False))
33
+ result = await pipeline.search("hello", rerank=True)
34
+ print(result["formatted_context"]) # [1]: ...
35
+ ```
@@ -0,0 +1,15 @@
1
+ % Troubleshooting
2
+
3
+ Pydantic UnsupportedFieldAttributeWarning
4
+ - Emitted by a dependency; harmless.
5
+ - Suppress if desired:
6
+ - `import warnings; warnings.filterwarnings("ignore", message=".*validate_default.*")`
7
+
8
+ "libmagic is unavailable"
9
+ - Improves filetype detection for Unstructured.
10
+ - Windows: `uv pip install python-magic-bin`
11
+ - Debian/Ubuntu: `apt-get install libmagic1` and `uv pip install python-magic`
12
+
13
+ "'doc_id' is deprecated and 'id_' will be used instead"
14
+ - LlamaIndex info; safe to ignore.
15
+ - Suppress: `logging.getLogger("llama_index").setLevel(logging.ERROR)`