socratic-rag 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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Socratic RAG Contributors
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.
@@ -0,0 +1,416 @@
1
+ Metadata-Version: 2.4
2
+ Name: socratic-rag
3
+ Version: 0.1.0
4
+ Summary: Production-grade Retrieval-Augmented Generation package
5
+ Author-email: Socratic RAG <info@socratic-rag.dev>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/Nireus79/Socratic-rag
8
+ Project-URL: Documentation, https://github.com/Nireus79/Socratic-rag/tree/main/docs
9
+ Project-URL: Repository, https://github.com/Nireus79/Socratic-rag.git
10
+ Project-URL: Issues, https://github.com/Nireus79/Socratic-rag/issues
11
+ Keywords: rag,retrieval-augmented-generation,nlp,embeddings,vector-database
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.8
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
+ Requires-Python: >=3.8
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: numpy>=1.20.0
27
+ Requires-Dist: sentence-transformers>=2.0.0
28
+ Provides-Extra: chromadb
29
+ Requires-Dist: chromadb>=0.4.0; extra == "chromadb"
30
+ Provides-Extra: qdrant
31
+ Requires-Dist: qdrant-client>=1.0.0; extra == "qdrant"
32
+ Provides-Extra: faiss
33
+ Requires-Dist: faiss-cpu>=1.7.0; extra == "faiss"
34
+ Provides-Extra: pinecone
35
+ Requires-Dist: pinecone-client>=2.0.0; extra == "pinecone"
36
+ Provides-Extra: pdf
37
+ Requires-Dist: PyPDF2>=3.0.0; extra == "pdf"
38
+ Provides-Extra: markdown
39
+ Requires-Dist: markdown>=3.0.0; extra == "markdown"
40
+ Provides-Extra: openclaw
41
+ Provides-Extra: langchain
42
+ Requires-Dist: langchain>=0.1.0; extra == "langchain"
43
+ Provides-Extra: nexus
44
+ Requires-Dist: socrates-nexus>=0.3.0; extra == "nexus"
45
+ Provides-Extra: all
46
+ Requires-Dist: chromadb>=0.4.0; extra == "all"
47
+ Requires-Dist: qdrant-client>=1.0.0; extra == "all"
48
+ Requires-Dist: faiss-cpu>=1.7.0; extra == "all"
49
+ Requires-Dist: PyPDF2>=3.0.0; extra == "all"
50
+ Requires-Dist: markdown>=3.0.0; extra == "all"
51
+ Requires-Dist: langchain>=0.1.0; extra == "all"
52
+ Requires-Dist: socrates-nexus>=0.3.0; extra == "all"
53
+ Provides-Extra: dev
54
+ Requires-Dist: pytest>=7.0; extra == "dev"
55
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
56
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
57
+ Requires-Dist: black>=23.0; extra == "dev"
58
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
59
+ Requires-Dist: mypy>=1.0; extra == "dev"
60
+ Dynamic: license-file
61
+
62
+ # Socratic RAG
63
+
64
+ Production-grade Retrieval-Augmented Generation (RAG) package for Python.
65
+
66
+ ## Features
67
+
68
+ - **Multiple Vector Databases**: ChromaDB, Qdrant, FAISS, Pinecone (with extensible provider pattern)
69
+ - **Flexible Embedding Providers**: Sentence Transformers, OpenAI (via Socrates Nexus)
70
+ - **Smart Chunking**: Fixed-size, semantic, and recursive chunking strategies
71
+ - **Document Processing**: Text, PDF, Markdown, and code files
72
+ - **Framework Integrations**: Openclaw skills and LangChain components
73
+ - **Async Support**: Full async/await interface for non-blocking operations
74
+ - **Production Ready**: 70%+ test coverage, type hints, comprehensive documentation
75
+
76
+ ## Installation
77
+
78
+ ### Basic Installation
79
+
80
+ ```bash
81
+ pip install socratic-rag
82
+ ```
83
+
84
+ ### With Optional Dependencies
85
+
86
+ ```bash
87
+ # All features
88
+ pip install socratic-rag[all]
89
+
90
+ # Specific vector stores
91
+ pip install socratic-rag[chromadb,qdrant,faiss]
92
+
93
+ # Document processing
94
+ pip install socratic-rag[pdf,markdown]
95
+
96
+ # Integrations
97
+ pip install socratic-rag[langchain,openclaw,nexus]
98
+
99
+ # Development
100
+ pip install socratic-rag[dev]
101
+ ```
102
+
103
+ ## Quick Start
104
+
105
+ ### Basic Usage
106
+
107
+ ```python
108
+ from socratic_rag import RAGClient
109
+
110
+ # Initialize client
111
+ client = RAGClient()
112
+
113
+ # Add documents
114
+ doc_id = client.add_document(
115
+ content="Python is a programming language created by Guido van Rossum.",
116
+ source="python_facts.txt"
117
+ )
118
+
119
+ # Search
120
+ results = client.search("What is Python?", top_k=5)
121
+ for result in results:
122
+ print(f"Score: {result.score:.2f}")
123
+ print(f"Text: {result.chunk.text}\n")
124
+
125
+ # Retrieve formatted context for LLM
126
+ context = client.retrieve_context("What is Python?")
127
+ print(context)
128
+ ```
129
+
130
+ ### Custom Configuration
131
+
132
+ ```python
133
+ from socratic_rag import RAGClient, RAGConfig
134
+
135
+ config = RAGConfig(
136
+ vector_store="chromadb",
137
+ embedder="sentence-transformers",
138
+ chunking_strategy="fixed",
139
+ chunk_size=512,
140
+ chunk_overlap=50,
141
+ top_k=5,
142
+ )
143
+
144
+ client = RAGClient(config)
145
+ ```
146
+
147
+ ### Async Usage
148
+
149
+ ```python
150
+ import asyncio
151
+ from socratic_rag import AsyncRAGClient
152
+
153
+ async def main():
154
+ client = AsyncRAGClient()
155
+
156
+ # Add documents asynchronously
157
+ doc_id = await client.add_document(
158
+ content="Document content",
159
+ source="source.txt"
160
+ )
161
+
162
+ # Search asynchronously
163
+ results = await client.search("query")
164
+
165
+ # Retrieve context asynchronously
166
+ context = await client.retrieve_context("query")
167
+
168
+ asyncio.run(main())
169
+ ```
170
+
171
+ ## Architecture
172
+
173
+ ### Provider Pattern
174
+
175
+ Socratic RAG uses an extensible provider pattern for easy integration of new components:
176
+
177
+ ```
178
+ RAGClient
179
+ ├── Embedder Provider (sentence-transformers, OpenAI, etc.)
180
+ ├── Chunker Provider (fixed, semantic, recursive)
181
+ └── Vector Store Provider (ChromaDB, Qdrant, FAISS, Pinecone)
182
+ ```
183
+
184
+ ### Core Models
185
+
186
+ - **Document**: Raw document with metadata
187
+ - **Chunk**: Text chunk with position and metadata
188
+ - **SearchResult**: Search result with relevance score
189
+ - **RAGConfig**: Configuration object
190
+
191
+ ## Examples
192
+
193
+ See the `examples/` directory for:
194
+
195
+ 1. `01_basic_rag.py` - Basic RAG workflow
196
+ 2. `02_qdrant_rag.py` - Using Qdrant vector store
197
+ 3. `03_faiss_rag.py` - Using FAISS vector store
198
+ 4. `04_document_processing.py` - Document processing
199
+ 5. `05_openclaw_integration.py` - Openclaw skill integration
200
+ 6. `06_langchain_integration.py` - LangChain integration
201
+ 7. `07_llm_powered_rag.py` - RAG with LLM (using Socrates Nexus)
202
+
203
+ ## Testing
204
+
205
+ Run the test suite:
206
+
207
+ ```bash
208
+ pytest tests/ -v --cov=socratic_rag
209
+ ```
210
+
211
+ Specific test categories:
212
+
213
+ ```bash
214
+ # Unit tests only
215
+ pytest tests/ -m unit
216
+
217
+ # Integration tests only
218
+ pytest tests/ -m integration
219
+
220
+ # Exclude slow tests
221
+ pytest tests/ -m "not slow"
222
+ ```
223
+
224
+ ## Vector Store Providers
225
+
226
+ ### ChromaDB (Default)
227
+
228
+ ```python
229
+ from socratic_rag import RAGClient, RAGConfig
230
+
231
+ config = RAGConfig(vector_store="chromadb")
232
+ client = RAGClient(config)
233
+ ```
234
+
235
+ ### Qdrant
236
+
237
+ ```python
238
+ config = RAGConfig(vector_store="qdrant")
239
+ client = RAGClient(config)
240
+ ```
241
+
242
+ ### FAISS
243
+
244
+ ```python
245
+ config = RAGConfig(vector_store="faiss")
246
+ client = RAGClient(config)
247
+ ```
248
+
249
+ ## Embedding Providers
250
+
251
+ ### Sentence Transformers (Default)
252
+
253
+ ```python
254
+ config = RAGConfig(embedder="sentence-transformers")
255
+ client = RAGClient(config)
256
+ ```
257
+
258
+ ### OpenAI (via Socrates Nexus)
259
+
260
+ ```python
261
+ config = RAGConfig(embedder="openai")
262
+ client = RAGClient(config)
263
+ ```
264
+
265
+ ## Document Processing
266
+
267
+ ### Text Files
268
+
269
+ ```python
270
+ from socratic_rag.processors import TextProcessor
271
+
272
+ processor = TextProcessor()
273
+ documents = processor.process("path/to/file.txt")
274
+ ```
275
+
276
+ ### PDF Files
277
+
278
+ ```python
279
+ from socratic_rag.processors import PDFProcessor
280
+
281
+ processor = PDFProcessor()
282
+ documents = processor.process("path/to/file.pdf")
283
+ ```
284
+
285
+ ### Markdown Files
286
+
287
+ ```python
288
+ from socratic_rag.processors import MarkdownProcessor
289
+
290
+ processor = MarkdownProcessor()
291
+ documents = processor.process("path/to/file.md")
292
+ ```
293
+
294
+ ## Framework Integrations
295
+
296
+ ### Openclaw
297
+
298
+ ```python
299
+ from socratic_rag.integrations.openclaw import SocraticRAGSkill
300
+
301
+ skill = SocraticRAGSkill(vector_store="chromadb")
302
+ skill.add_document("content", "source.txt")
303
+ results = skill.search("query")
304
+ ```
305
+
306
+ ### LangChain
307
+
308
+ ```python
309
+ from socratic_rag.integrations.langchain import SocraticRAGRetriever
310
+ from langchain.chat_models import ChatAnthropic
311
+ from langchain.chains import RetrievalQA
312
+
313
+ retriever = SocraticRAGRetriever(client=rag_client, top_k=5)
314
+ llm = ChatAnthropic(model="claude-sonnet")
315
+ qa = RetrievalQA.from_chain_type(llm=llm, retriever=retriever)
316
+
317
+ answer = qa.run("What is Python?")
318
+ ```
319
+
320
+ ## API Reference
321
+
322
+ ### RAGClient
323
+
324
+ #### Methods
325
+
326
+ - `add_document(content, source, metadata=None) -> str` - Add document to knowledge base
327
+ - `search(query, top_k=None, filters=None) -> List[SearchResult]` - Search for relevant documents
328
+ - `retrieve_context(query, top_k=None) -> str` - Retrieve formatted context for LLM
329
+ - `clear() -> bool` - Clear all documents
330
+
331
+ ### AsyncRAGClient
332
+
333
+ Same methods as RAGClient but with async/await.
334
+
335
+ ## Configuration Options
336
+
337
+ ```python
338
+ RAGConfig(
339
+ vector_store="chromadb", # Vector store provider
340
+ embedder="sentence-transformers", # Embedding provider
341
+ chunking_strategy="fixed", # Chunking strategy
342
+ chunk_size=512, # Characters per chunk
343
+ chunk_overlap=50, # Overlap between chunks
344
+ top_k=5, # Default number of results
345
+ embedding_cache=True, # Cache embeddings
346
+ cache_ttl=3600, # Cache TTL in seconds
347
+ collection_name="socratic_rag", # Collection name
348
+ )
349
+ ```
350
+
351
+ ## Exceptions
352
+
353
+ - `SocraticRAGError` - Base exception
354
+ - `ConfigurationError` - Configuration validation error
355
+ - `VectorStoreError` - Vector store operation error
356
+ - `EmbeddingError` - Embedding operation error
357
+ - `ChunkingError` - Chunking operation error
358
+ - `ProcessorError` - Document processing error
359
+ - `DocumentNotFoundError` - Document not found
360
+ - `ProviderNotFoundError` - Provider not found
361
+
362
+ ## Performance Tips
363
+
364
+ 1. **Use appropriate chunk size**: Smaller chunks (256-512) for dense retrieval, larger (1024+) for sparse
365
+ 2. **Set overlap wisely**: 10-15% overlap usually works well
366
+ 3. **Cache embeddings**: Enable embedding cache for repeated queries
367
+ 4. **Batch operations**: Use `embed_batch()` for multiple embeddings
368
+ 5. **Choose right embedder**: Sentence Transformers for local, OpenAI for production scale
369
+
370
+ ## Contributing
371
+
372
+ Contributions are welcome! Please see `CONTRIBUTING.md` for guidelines.
373
+
374
+ ## License
375
+
376
+ MIT License - see `LICENSE` file for details
377
+
378
+ ## Citation
379
+
380
+ If you use Socratic RAG in your research, please cite:
381
+
382
+ ```bibtex
383
+ @software{socratic_rag_2024,
384
+ title={Socratic RAG: Production-grade Retrieval-Augmented Generation},
385
+ author={Your Name},
386
+ year={2024},
387
+ url={https://github.com/Nireus79/Socratic-rag}
388
+ }
389
+ ```
390
+
391
+ ## Roadmap
392
+
393
+ ### v0.1.0 (Current)
394
+ - ✅ Core RAG functionality
395
+ - ✅ ChromaDB vector store
396
+ - ✅ Sentence Transformers embeddings
397
+ - ✅ Fixed-size chunking
398
+ - ✅ Openclaw integration
399
+ - ✅ LangChain integration
400
+
401
+ ### v0.2.0
402
+ - Qdrant and FAISS vector stores
403
+ - Semantic chunking
404
+ - Pinecone cloud provider
405
+ - Vision model support
406
+
407
+ ### v0.3.0
408
+ - Hybrid search (vector + keyword)
409
+ - Re-ranking with cross-encoders
410
+ - Multi-language support
411
+
412
+ ## Support
413
+
414
+ For issues, questions, or suggestions:
415
+ - GitHub Issues: https://github.com/Nireus79/Socratic-rag/issues
416
+ - Discussions: https://github.com/Nireus79/Socratic-rag/discussions