dataknobs-bots 0.2.4__py3-none-any.whl
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.
- dataknobs_bots/__init__.py +42 -0
- dataknobs_bots/api/__init__.py +42 -0
- dataknobs_bots/api/dependencies.py +140 -0
- dataknobs_bots/api/exceptions.py +289 -0
- dataknobs_bots/bot/__init__.py +15 -0
- dataknobs_bots/bot/base.py +1091 -0
- dataknobs_bots/bot/context.py +102 -0
- dataknobs_bots/bot/manager.py +430 -0
- dataknobs_bots/bot/registry.py +629 -0
- dataknobs_bots/config/__init__.py +39 -0
- dataknobs_bots/config/resolution.py +353 -0
- dataknobs_bots/knowledge/__init__.py +82 -0
- dataknobs_bots/knowledge/query/__init__.py +25 -0
- dataknobs_bots/knowledge/query/expander.py +262 -0
- dataknobs_bots/knowledge/query/transformer.py +288 -0
- dataknobs_bots/knowledge/rag.py +738 -0
- dataknobs_bots/knowledge/retrieval/__init__.py +23 -0
- dataknobs_bots/knowledge/retrieval/formatter.py +249 -0
- dataknobs_bots/knowledge/retrieval/merger.py +279 -0
- dataknobs_bots/memory/__init__.py +56 -0
- dataknobs_bots/memory/base.py +38 -0
- dataknobs_bots/memory/buffer.py +58 -0
- dataknobs_bots/memory/vector.py +188 -0
- dataknobs_bots/middleware/__init__.py +11 -0
- dataknobs_bots/middleware/base.py +92 -0
- dataknobs_bots/middleware/cost.py +421 -0
- dataknobs_bots/middleware/logging.py +184 -0
- dataknobs_bots/reasoning/__init__.py +65 -0
- dataknobs_bots/reasoning/base.py +50 -0
- dataknobs_bots/reasoning/react.py +299 -0
- dataknobs_bots/reasoning/simple.py +51 -0
- dataknobs_bots/registry/__init__.py +41 -0
- dataknobs_bots/registry/backend.py +181 -0
- dataknobs_bots/registry/memory.py +244 -0
- dataknobs_bots/registry/models.py +102 -0
- dataknobs_bots/registry/portability.py +210 -0
- dataknobs_bots/tools/__init__.py +5 -0
- dataknobs_bots/tools/knowledge_search.py +113 -0
- dataknobs_bots/utils/__init__.py +1 -0
- dataknobs_bots-0.2.4.dist-info/METADATA +591 -0
- dataknobs_bots-0.2.4.dist-info/RECORD +42 -0
- dataknobs_bots-0.2.4.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,591 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dataknobs-bots
|
|
3
|
+
Version: 0.2.4
|
|
4
|
+
Summary: Configuration-driven AI agents for DataKnobs
|
|
5
|
+
Author-email: Spence Koehler <KoehlerSB747@gmail.com>
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Requires-Dist: dataknobs-common>=1.0.1
|
|
8
|
+
Requires-Dist: dataknobs-config>=0.2.0
|
|
9
|
+
Requires-Dist: dataknobs-data>=0.3.1
|
|
10
|
+
Requires-Dist: dataknobs-fsm>=0.1.2
|
|
11
|
+
Requires-Dist: dataknobs-llm>=0.1.0
|
|
12
|
+
Requires-Dist: dataknobs-xization>=1.1.0
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
# DataKnobs Bots
|
|
16
|
+
|
|
17
|
+
**Configuration-driven AI agents and chatbots for the DataKnobs ecosystem**
|
|
18
|
+
|
|
19
|
+
[](https://www.python.org/downloads/)
|
|
20
|
+
[](LICENSE)
|
|
21
|
+
|
|
22
|
+
## Overview
|
|
23
|
+
|
|
24
|
+
DynaBot is a flexible, configuration-driven framework for building AI agents and chatbots. It provides a complete solution for multi-tenant AI deployments with features like memory management, knowledge retrieval (RAG), tool integration, and advanced reasoning strategies.
|
|
25
|
+
|
|
26
|
+
### Key Features
|
|
27
|
+
|
|
28
|
+
- **Configuration-First Design** - Define bot behavior entirely through YAML/JSON configuration
|
|
29
|
+
- **Multi-Tenant Architecture** - Single bot instance serves multiple clients with isolated conversations
|
|
30
|
+
- **Flexible Memory Systems** - Buffer, summary, and vector memory implementations
|
|
31
|
+
- **RAG Support** - Built-in knowledge base with document chunking and vector search
|
|
32
|
+
- **Tool Integration** - Load and configure tools from configuration without code changes
|
|
33
|
+
- **Reasoning Strategies** - Simple, Chain-of-Thought, and ReAct reasoning
|
|
34
|
+
- **Ecosystem Integration** - Seamlessly integrates with dataknobs-config, dataknobs-llm, dataknobs-data, and dataknobs-xization
|
|
35
|
+
- **Stateless Design** - Perfect for horizontal scaling in containerized environments
|
|
36
|
+
- **Production Ready** - PostgreSQL storage, error handling, and logging
|
|
37
|
+
|
|
38
|
+
## Table of Contents
|
|
39
|
+
|
|
40
|
+
- [Installation](#installation)
|
|
41
|
+
- [Quick Start](#quick-start)
|
|
42
|
+
- [Core Concepts](#core-concepts)
|
|
43
|
+
- [Configuration](#configuration)
|
|
44
|
+
- [Examples](#examples)
|
|
45
|
+
- [Documentation](#documentation)
|
|
46
|
+
- [Development](#development)
|
|
47
|
+
- [License](#license)
|
|
48
|
+
|
|
49
|
+
## Installation
|
|
50
|
+
|
|
51
|
+
Install using pip or uv:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
# Using pip
|
|
55
|
+
pip install dataknobs-bots
|
|
56
|
+
|
|
57
|
+
# Using uv
|
|
58
|
+
uv pip install dataknobs-bots
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Optional Dependencies
|
|
62
|
+
|
|
63
|
+
For specific features, install optional dependencies:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
# PostgreSQL storage
|
|
67
|
+
pip install dataknobs-bots[postgres]
|
|
68
|
+
|
|
69
|
+
# Vector memory with FAISS
|
|
70
|
+
pip install dataknobs-bots[faiss]
|
|
71
|
+
|
|
72
|
+
# All optional dependencies
|
|
73
|
+
pip install dataknobs-bots[all]
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Quick Start
|
|
77
|
+
|
|
78
|
+
### Simple Chatbot
|
|
79
|
+
|
|
80
|
+
Create a basic chatbot with memory:
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
import asyncio
|
|
84
|
+
from dataknobs_bots import DynaBot, BotContext
|
|
85
|
+
|
|
86
|
+
async def main():
|
|
87
|
+
# Configuration
|
|
88
|
+
config = {
|
|
89
|
+
"llm": {
|
|
90
|
+
"provider": "ollama",
|
|
91
|
+
"model": "gemma3:1b",
|
|
92
|
+
"temperature": 0.7,
|
|
93
|
+
"max_tokens": 1000
|
|
94
|
+
},
|
|
95
|
+
"conversation_storage": {
|
|
96
|
+
"backend": "memory"
|
|
97
|
+
},
|
|
98
|
+
"memory": {
|
|
99
|
+
"type": "buffer",
|
|
100
|
+
"max_messages": 10
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
# Create bot from configuration
|
|
105
|
+
bot = await DynaBot.from_config(config)
|
|
106
|
+
|
|
107
|
+
# Create conversation context
|
|
108
|
+
context = BotContext(
|
|
109
|
+
conversation_id="conv-001",
|
|
110
|
+
client_id="demo-client",
|
|
111
|
+
user_id="user-123"
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
# Chat with the bot
|
|
115
|
+
response = await bot.chat("Hello! What can you help me with?", context)
|
|
116
|
+
print(f"Bot: {response}")
|
|
117
|
+
|
|
118
|
+
response = await bot.chat("Tell me about yourself", context)
|
|
119
|
+
print(f"Bot: {response}")
|
|
120
|
+
|
|
121
|
+
if __name__ == "__main__":
|
|
122
|
+
asyncio.run(main())
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### RAG Chatbot with Knowledge Base
|
|
126
|
+
|
|
127
|
+
Create a bot with knowledge retrieval:
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
config = {
|
|
131
|
+
"llm": {
|
|
132
|
+
"provider": "ollama",
|
|
133
|
+
"model": "gemma3:1b"
|
|
134
|
+
},
|
|
135
|
+
"conversation_storage": {
|
|
136
|
+
"backend": "memory"
|
|
137
|
+
},
|
|
138
|
+
"knowledge_base": {
|
|
139
|
+
"enabled": True,
|
|
140
|
+
"documents_path": "./docs",
|
|
141
|
+
"vector_store": {
|
|
142
|
+
"backend": "faiss",
|
|
143
|
+
"dimension": 384
|
|
144
|
+
},
|
|
145
|
+
"embedding_provider": "ollama",
|
|
146
|
+
"embedding_model": "nomic-embed-text"
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
bot = await DynaBot.from_config(config)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### ReAct Agent with Tools
|
|
154
|
+
|
|
155
|
+
Create an agent that can use tools:
|
|
156
|
+
|
|
157
|
+
```python
|
|
158
|
+
config = {
|
|
159
|
+
"llm": {
|
|
160
|
+
"provider": "ollama",
|
|
161
|
+
"model": "phi3:mini"
|
|
162
|
+
},
|
|
163
|
+
"conversation_storage": {
|
|
164
|
+
"backend": "memory"
|
|
165
|
+
},
|
|
166
|
+
"reasoning": {
|
|
167
|
+
"strategy": "react",
|
|
168
|
+
"max_iterations": 5,
|
|
169
|
+
"verbose": True
|
|
170
|
+
},
|
|
171
|
+
"tools": [
|
|
172
|
+
{
|
|
173
|
+
"class": "my_tools.CalculatorTool",
|
|
174
|
+
"params": {"precision": 2}
|
|
175
|
+
}
|
|
176
|
+
]
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
bot = await DynaBot.from_config(config)
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Environment-Aware Configuration
|
|
183
|
+
|
|
184
|
+
DynaBot supports **environment-aware configuration** for deploying the same bot across different environments. This separates portable bot behavior from environment-specific infrastructure.
|
|
185
|
+
|
|
186
|
+
### Portable Bot Configs
|
|
187
|
+
|
|
188
|
+
Bot configs use **logical resource references** instead of hardcoded infrastructure:
|
|
189
|
+
|
|
190
|
+
```yaml
|
|
191
|
+
# config/bots/assistant.yaml - PORTABLE
|
|
192
|
+
bot:
|
|
193
|
+
llm:
|
|
194
|
+
$resource: default # Logical name
|
|
195
|
+
type: llm_providers # Resource type
|
|
196
|
+
temperature: 0.7 # Behavioral setting
|
|
197
|
+
|
|
198
|
+
conversation_storage:
|
|
199
|
+
$resource: conversations
|
|
200
|
+
type: databases
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Environment-Specific Bindings
|
|
204
|
+
|
|
205
|
+
Environment configs define concrete implementations:
|
|
206
|
+
|
|
207
|
+
```yaml
|
|
208
|
+
# config/environments/development.yaml
|
|
209
|
+
name: development
|
|
210
|
+
resources:
|
|
211
|
+
llm_providers:
|
|
212
|
+
default:
|
|
213
|
+
provider: ollama
|
|
214
|
+
model: qwen3:8b
|
|
215
|
+
databases:
|
|
216
|
+
conversations:
|
|
217
|
+
backend: memory
|
|
218
|
+
|
|
219
|
+
# config/environments/production.yaml
|
|
220
|
+
name: production
|
|
221
|
+
resources:
|
|
222
|
+
llm_providers:
|
|
223
|
+
default:
|
|
224
|
+
provider: openai
|
|
225
|
+
model: gpt-4
|
|
226
|
+
api_key: ${OPENAI_API_KEY}
|
|
227
|
+
databases:
|
|
228
|
+
conversations:
|
|
229
|
+
backend: postgres
|
|
230
|
+
connection_string: ${DATABASE_URL}
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### Resolving Resources
|
|
234
|
+
|
|
235
|
+
```python
|
|
236
|
+
from dataknobs_config import EnvironmentConfig
|
|
237
|
+
from dataknobs_bots.config import BotResourceResolver
|
|
238
|
+
|
|
239
|
+
# Auto-detects environment from DATAKNOBS_ENVIRONMENT
|
|
240
|
+
env = EnvironmentConfig.load()
|
|
241
|
+
resolver = BotResourceResolver(env)
|
|
242
|
+
|
|
243
|
+
# Get initialized resources
|
|
244
|
+
llm = await resolver.get_llm("default")
|
|
245
|
+
db = await resolver.get_database("conversations")
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
See [docs/CONFIGURATION.md](docs/CONFIGURATION.md#environment-aware-configuration) for complete documentation.
|
|
249
|
+
|
|
250
|
+
## Core Concepts
|
|
251
|
+
|
|
252
|
+
### DynaBot
|
|
253
|
+
|
|
254
|
+
The main bot class that orchestrates all components. Created from configuration and handles:
|
|
255
|
+
- Message processing
|
|
256
|
+
- Conversation management
|
|
257
|
+
- Memory integration
|
|
258
|
+
- Knowledge retrieval
|
|
259
|
+
- Tool execution
|
|
260
|
+
- Reasoning strategies
|
|
261
|
+
|
|
262
|
+
### BotContext
|
|
263
|
+
|
|
264
|
+
Encapsulates execution context for each bot interaction:
|
|
265
|
+
- `conversation_id` - Unique ID for the conversation
|
|
266
|
+
- `client_id` - Tenant/client identifier
|
|
267
|
+
- `user_id` - User identifier
|
|
268
|
+
- `session_metadata` - Additional metadata
|
|
269
|
+
|
|
270
|
+
### Memory Systems
|
|
271
|
+
|
|
272
|
+
Three types of memory for context management:
|
|
273
|
+
|
|
274
|
+
1. **Buffer Memory** - Simple sliding window of recent messages
|
|
275
|
+
2. **Summary Memory** - Compressed summaries of conversation history
|
|
276
|
+
3. **Vector Memory** - Semantic search over conversation history
|
|
277
|
+
|
|
278
|
+
### Knowledge Base (RAG)
|
|
279
|
+
|
|
280
|
+
Retrieval Augmented Generation support with:
|
|
281
|
+
- Document ingestion and chunking
|
|
282
|
+
- Vector embeddings
|
|
283
|
+
- Semantic search
|
|
284
|
+
- Context injection
|
|
285
|
+
|
|
286
|
+
### Reasoning Strategies
|
|
287
|
+
|
|
288
|
+
1. **Simple** - Direct LLM response
|
|
289
|
+
2. **Chain-of-Thought** - Step-by-step reasoning
|
|
290
|
+
3. **ReAct** - Reasoning + Acting with tools
|
|
291
|
+
|
|
292
|
+
### Tools
|
|
293
|
+
|
|
294
|
+
Tools extend bot capabilities with external functions. Loaded from configuration:
|
|
295
|
+
|
|
296
|
+
```python
|
|
297
|
+
"tools": [
|
|
298
|
+
# Direct instantiation
|
|
299
|
+
{
|
|
300
|
+
"class": "my_tools.CalculatorTool",
|
|
301
|
+
"params": {"precision": 3}
|
|
302
|
+
},
|
|
303
|
+
# XRef to predefined tool
|
|
304
|
+
"xref:tools[my_calculator]"
|
|
305
|
+
]
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
## Configuration
|
|
309
|
+
|
|
310
|
+
DynaBot uses a configuration-first approach. All bot behavior is defined through configuration.
|
|
311
|
+
|
|
312
|
+
### Basic Configuration Structure
|
|
313
|
+
|
|
314
|
+
```yaml
|
|
315
|
+
# LLM Configuration
|
|
316
|
+
llm:
|
|
317
|
+
provider: ollama
|
|
318
|
+
model: gemma3:1b
|
|
319
|
+
temperature: 0.7
|
|
320
|
+
max_tokens: 1000
|
|
321
|
+
|
|
322
|
+
# Conversation Storage
|
|
323
|
+
conversation_storage:
|
|
324
|
+
backend: memory # or postgres
|
|
325
|
+
|
|
326
|
+
# Optional: Memory
|
|
327
|
+
memory:
|
|
328
|
+
type: buffer
|
|
329
|
+
max_messages: 10
|
|
330
|
+
|
|
331
|
+
# Optional: Knowledge Base
|
|
332
|
+
knowledge_base:
|
|
333
|
+
enabled: true
|
|
334
|
+
documents_path: ./docs
|
|
335
|
+
vector_store:
|
|
336
|
+
backend: faiss
|
|
337
|
+
dimension: 384
|
|
338
|
+
embedding_provider: ollama
|
|
339
|
+
embedding_model: nomic-embed-text
|
|
340
|
+
|
|
341
|
+
# Optional: Reasoning
|
|
342
|
+
reasoning:
|
|
343
|
+
strategy: react
|
|
344
|
+
max_iterations: 5
|
|
345
|
+
verbose: true
|
|
346
|
+
|
|
347
|
+
# Optional: Tools
|
|
348
|
+
tools:
|
|
349
|
+
- class: my_tools.CalculatorTool
|
|
350
|
+
params:
|
|
351
|
+
precision: 2
|
|
352
|
+
|
|
353
|
+
# Optional: System Prompt
|
|
354
|
+
prompts:
|
|
355
|
+
helpful_assistant: "You are a helpful AI assistant."
|
|
356
|
+
|
|
357
|
+
system_prompt:
|
|
358
|
+
name: helpful_assistant
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
See [docs/CONFIGURATION.md](docs/CONFIGURATION.md) for complete configuration reference.
|
|
362
|
+
|
|
363
|
+
## Examples
|
|
364
|
+
|
|
365
|
+
The `examples/` directory contains working examples demonstrating various features:
|
|
366
|
+
|
|
367
|
+
1. **Simple Chatbot** (`01_simple_chatbot.py`) - Basic conversational bot
|
|
368
|
+
2. **Chatbot with Memory** (`02_chatbot_with_memory.py`) - Buffer memory for context
|
|
369
|
+
3. **RAG Chatbot** (`03_rag_chatbot.py`) - Knowledge base integration
|
|
370
|
+
4. **ReAct Agent** (`04_react_agent.py`) - Tool-using agent with reasoning
|
|
371
|
+
5. **Multi-Tenant Bot** (`05_multi_tenant.py`) - Multiple clients, isolated conversations
|
|
372
|
+
6. **Config-Based Tools** (`06_config_based_tools.py`) - Configuration-driven tool loading
|
|
373
|
+
|
|
374
|
+
### Running Examples
|
|
375
|
+
|
|
376
|
+
All examples use Ollama for local LLM inference:
|
|
377
|
+
|
|
378
|
+
```bash
|
|
379
|
+
# Install Ollama: https://ollama.ai/
|
|
380
|
+
|
|
381
|
+
# Pull required models
|
|
382
|
+
ollama pull gemma3:1b
|
|
383
|
+
ollama pull phi3:mini
|
|
384
|
+
ollama pull nomic-embed-text
|
|
385
|
+
|
|
386
|
+
# Run an example
|
|
387
|
+
python examples/01_simple_chatbot.py
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
See [examples/README.md](examples/README.md) for detailed information on each example.
|
|
391
|
+
|
|
392
|
+
## Documentation
|
|
393
|
+
|
|
394
|
+
### User Documentation
|
|
395
|
+
|
|
396
|
+
- [User Guide](docs/USER_GUIDE.md) - Tutorials and how-to guides
|
|
397
|
+
- [Configuration Reference](docs/CONFIGURATION.md) - Complete configuration options
|
|
398
|
+
- [Environment-Aware Configuration](docs/CONFIGURATION.md#environment-aware-configuration) - Portable configs for multi-environment deployments
|
|
399
|
+
- [Migration Guide](docs/MIGRATION.md) - Migrate existing configs to environment-aware pattern
|
|
400
|
+
- [Tools Development](docs/TOOLS.md) - Creating and configuring tools
|
|
401
|
+
|
|
402
|
+
### Developer Documentation
|
|
403
|
+
|
|
404
|
+
- [API Reference](docs/API.md) - Complete API documentation
|
|
405
|
+
- [Architecture](docs/ARCHITECTURE.md) - System design and components
|
|
406
|
+
- [Examples](examples/README.md) - Working code examples
|
|
407
|
+
|
|
408
|
+
## Development
|
|
409
|
+
|
|
410
|
+
### Setup Development Environment
|
|
411
|
+
|
|
412
|
+
```bash
|
|
413
|
+
# Clone the repository
|
|
414
|
+
git clone https://github.com/kbs-labs/dataknobs.git
|
|
415
|
+
cd dataknobs/packages/bots
|
|
416
|
+
|
|
417
|
+
# Install dependencies with development extras
|
|
418
|
+
uv pip install -e ".[dev]"
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
### Running Tests
|
|
422
|
+
|
|
423
|
+
```bash
|
|
424
|
+
# Run all tests
|
|
425
|
+
pytest
|
|
426
|
+
|
|
427
|
+
# Run with coverage
|
|
428
|
+
pytest --cov=dataknobs_bots --cov-report=html
|
|
429
|
+
|
|
430
|
+
# Run specific test file
|
|
431
|
+
pytest tests/unit/test_dynabot.py
|
|
432
|
+
|
|
433
|
+
# Run integration tests (requires Ollama)
|
|
434
|
+
TEST_OLLAMA=true pytest tests/integration/
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
### Code Quality
|
|
438
|
+
|
|
439
|
+
```bash
|
|
440
|
+
# Format code
|
|
441
|
+
black src/ tests/
|
|
442
|
+
|
|
443
|
+
# Lint code
|
|
444
|
+
ruff check src/ tests/
|
|
445
|
+
|
|
446
|
+
# Type checking
|
|
447
|
+
mypy src/
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
### Project Structure
|
|
451
|
+
|
|
452
|
+
```
|
|
453
|
+
packages/bots/
|
|
454
|
+
├── src/dataknobs_bots/
|
|
455
|
+
│ ├── bot/ # Core bot implementation
|
|
456
|
+
│ │ ├── base.py # DynaBot class
|
|
457
|
+
│ │ ├── context.py # BotContext class
|
|
458
|
+
│ │ └── registry.py # Bot registry
|
|
459
|
+
│ ├── memory/ # Memory implementations
|
|
460
|
+
│ │ ├── base.py # Memory interface
|
|
461
|
+
│ │ ├── buffer.py # Buffer memory
|
|
462
|
+
│ │ └── vector.py # Vector memory
|
|
463
|
+
│ ├── knowledge/ # RAG implementation
|
|
464
|
+
│ │ └── rag.py # Knowledge base
|
|
465
|
+
│ ├── reasoning/ # Reasoning strategies
|
|
466
|
+
│ │ ├── base.py # Reasoning interface
|
|
467
|
+
│ │ ├── simple.py # Simple reasoning
|
|
468
|
+
│ │ └── react.py # ReAct reasoning
|
|
469
|
+
│ ├── tools/ # Built-in tools
|
|
470
|
+
│ │ └── knowledge_search.py
|
|
471
|
+
│ └── utils/ # Utilities
|
|
472
|
+
├── tests/
|
|
473
|
+
│ ├── unit/ # Unit tests
|
|
474
|
+
│ ├── integration/ # Integration tests
|
|
475
|
+
│ └── fixtures/ # Test fixtures
|
|
476
|
+
├── examples/ # Working examples
|
|
477
|
+
├── docs/ # Documentation
|
|
478
|
+
└── README.md # This file
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
## Use Cases
|
|
482
|
+
|
|
483
|
+
### Customer Support Bot
|
|
484
|
+
|
|
485
|
+
Multi-tenant bot with knowledge base for customer support:
|
|
486
|
+
|
|
487
|
+
```python
|
|
488
|
+
config = {
|
|
489
|
+
"llm": {"provider": "openai", "model": "gpt-4"},
|
|
490
|
+
"conversation_storage": {"backend": "postgres"},
|
|
491
|
+
"memory": {"type": "buffer", "max_messages": 20},
|
|
492
|
+
"knowledge_base": {
|
|
493
|
+
"enabled": True,
|
|
494
|
+
"documents_path": "./support_docs"
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
### Personal Assistant
|
|
500
|
+
|
|
501
|
+
Agent with tools for task automation:
|
|
502
|
+
|
|
503
|
+
```python
|
|
504
|
+
config = {
|
|
505
|
+
"llm": {"provider": "anthropic", "model": "claude-3-sonnet"},
|
|
506
|
+
"reasoning": {"strategy": "react"},
|
|
507
|
+
"tools": [
|
|
508
|
+
{"class": "tools.CalendarTool", "params": {}},
|
|
509
|
+
{"class": "tools.EmailTool", "params": {}},
|
|
510
|
+
{"class": "tools.WeatherTool", "params": {}}
|
|
511
|
+
]
|
|
512
|
+
}
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
### Document Q&A
|
|
516
|
+
|
|
517
|
+
RAG-powered document question answering:
|
|
518
|
+
|
|
519
|
+
```python
|
|
520
|
+
config = {
|
|
521
|
+
"llm": {"provider": "ollama", "model": "llama3.1:8b"},
|
|
522
|
+
"knowledge_base": {
|
|
523
|
+
"enabled": True,
|
|
524
|
+
"documents_path": "./company_docs",
|
|
525
|
+
"chunking": {"max_chunk_size": 500, "chunk_overlap": 50}
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
## Performance Considerations
|
|
531
|
+
|
|
532
|
+
### Scaling
|
|
533
|
+
|
|
534
|
+
- **Stateless Design** - Each request is independent, enabling horizontal scaling
|
|
535
|
+
- **Connection Pooling** - PostgreSQL connection pooling for high concurrency
|
|
536
|
+
- **Caching** - In-memory conversation caching reduces database queries
|
|
537
|
+
- **Async/Await** - Fully asynchronous for high throughput
|
|
538
|
+
|
|
539
|
+
### Optimization Tips
|
|
540
|
+
|
|
541
|
+
1. **Use Buffer Memory** - Faster than vector memory for most use cases
|
|
542
|
+
2. **Limit Memory Window** - Keep `max_messages` reasonable (10-20)
|
|
543
|
+
3. **PostgreSQL for Production** - Don't use in-memory storage in production
|
|
544
|
+
4. **Batch Knowledge Base Indexing** - Index documents offline
|
|
545
|
+
5. **Use Local LLMs** - Ollama for reduced latency and cost
|
|
546
|
+
|
|
547
|
+
## Contributing
|
|
548
|
+
|
|
549
|
+
Contributions are welcome! Please:
|
|
550
|
+
|
|
551
|
+
1. Fork the repository
|
|
552
|
+
2. Create a feature branch
|
|
553
|
+
3. Add tests for new functionality
|
|
554
|
+
4. Ensure all tests pass
|
|
555
|
+
5. Submit a pull request
|
|
556
|
+
|
|
557
|
+
See [CONTRIBUTING.md](../../CONTRIBUTING.md) for detailed guidelines.
|
|
558
|
+
|
|
559
|
+
## License
|
|
560
|
+
|
|
561
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
562
|
+
|
|
563
|
+
## Support
|
|
564
|
+
|
|
565
|
+
- **Issues**: [GitHub Issues](https://github.com/kbs-labs/dataknobs/issues)
|
|
566
|
+
- **Discussions**: [GitHub Discussions](https://github.com/kbs-labs/dataknobs/discussions)
|
|
567
|
+
- **Documentation**: [docs/](docs/)
|
|
568
|
+
- **Examples**: [examples/](examples/)
|
|
569
|
+
|
|
570
|
+
## Acknowledgments
|
|
571
|
+
|
|
572
|
+
Built on the DataKnobs ecosystem:
|
|
573
|
+
- [dataknobs-config](../config/) - Configuration management
|
|
574
|
+
- [dataknobs-llm](../llm/) - LLM providers and tools
|
|
575
|
+
- [dataknobs-data](../data/) - Data storage backends
|
|
576
|
+
- [dataknobs-xization](../xization/) - Configuration resolution
|
|
577
|
+
|
|
578
|
+
## Roadmap
|
|
579
|
+
|
|
580
|
+
- [ ] Streaming responses
|
|
581
|
+
- [ ] Multi-modal support (images, audio)
|
|
582
|
+
- [ ] Advanced memory strategies (hybrid, hierarchical)
|
|
583
|
+
- [ ] Tool marketplace
|
|
584
|
+
- [ ] Web UI for bot management
|
|
585
|
+
- [ ] Performance monitoring and analytics
|
|
586
|
+
- [ ] A/B testing framework
|
|
587
|
+
- [ ] Voice interface support
|
|
588
|
+
|
|
589
|
+
---
|
|
590
|
+
|
|
591
|
+
Made with ❤️ by the DataKnobs team
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
dataknobs_bots/__init__.py,sha256=h_PqsqssRQm0-oQeDBUSNMnqB5Tpun6o1s_VlbveJRw,1067
|
|
2
|
+
dataknobs_bots/api/__init__.py,sha256=Vf32_1KWpUvFr7_jYpZ12zjrosj5UdZpX8QYc6jV1Ew,920
|
|
3
|
+
dataknobs_bots/api/dependencies.py,sha256=3mkNzVgfqD-n7wsCLxYhTjuJ6uDIPua1FT2AJ1su8z0,3689
|
|
4
|
+
dataknobs_bots/api/exceptions.py,sha256=BO0qBCjRc0FDkK4WtPpcPCZeI6WX7Ib7DOAOPbanGBI,8040
|
|
5
|
+
dataknobs_bots/bot/__init__.py,sha256=NylKgjrImE8f15nR2Gkfxyze9fLbz0zZZT5ERkrk7Pw,339
|
|
6
|
+
dataknobs_bots/bot/base.py,sha256=DWJ-cSvuthkJ0ARVLhpoUUJFFDXaIyo0lW2NOHZLaXo,42984
|
|
7
|
+
dataknobs_bots/bot/context.py,sha256=PW8UD27N_j5eWGSp90x9KgPNdtyZ0lq5ri6adI754NY,3215
|
|
8
|
+
dataknobs_bots/bot/manager.py,sha256=IFShheQbQMdrPyoGqpkeJwFxYiD9uEocNVlgskhQ5uQ,15153
|
|
9
|
+
dataknobs_bots/bot/registry.py,sha256=IYaMZzUDzk74U-De8RdJ9zry1jBCcpRtKcXeYxm37YY,20828
|
|
10
|
+
dataknobs_bots/config/__init__.py,sha256=ua6XCJR3EcdVZi56qtKIFvLcU3HZuDLvKn4fJzshKt8,1140
|
|
11
|
+
dataknobs_bots/config/resolution.py,sha256=HSGz15jr_SfIjk81pVez4_381frMreHv2JpfIB9Qt4I,11074
|
|
12
|
+
dataknobs_bots/knowledge/__init__.py,sha256=ckeFPWexTPOl-ah8S5uwjofnprreKdhHdOQMC0AKJmE,2164
|
|
13
|
+
dataknobs_bots/knowledge/rag.py,sha256=UnUjvpvFDrsPxj51IusVB60xQca2d7fdeQXGSCjkSGI,25666
|
|
14
|
+
dataknobs_bots/knowledge/query/__init__.py,sha256=4tNAx1LQdp96pbMqe7r_PQj7lhxHtScJ3g4Ui0Oovqc,595
|
|
15
|
+
dataknobs_bots/knowledge/query/expander.py,sha256=hUreBchr0ljQgE6Qi2UCf53x5_AzGUhQvOiY3WCSHL4,8162
|
|
16
|
+
dataknobs_bots/knowledge/query/transformer.py,sha256=Ah7ulsRd0F-BWyRF_U5_ZHOFUhiy3AetfpvADtW0HjA,8746
|
|
17
|
+
dataknobs_bots/knowledge/retrieval/__init__.py,sha256=7xxdwoBzpsPcCR77SUYMPIbtLMLwnzVz7DsZENyPRwI,532
|
|
18
|
+
dataknobs_bots/knowledge/retrieval/formatter.py,sha256=F9PD6cs7P-H-RKY3YDNWkxquFnSeV-eI8W4n5otkqfE,7942
|
|
19
|
+
dataknobs_bots/knowledge/retrieval/merger.py,sha256=25lHca_2oA1g4o_WNSiOJOHz_H7PVFUyfSLdctocmMk,8922
|
|
20
|
+
dataknobs_bots/memory/__init__.py,sha256=oNhToZM8SkBd3REeih9HtT7UKsv_f6xmKu6bEUYhqEU,1493
|
|
21
|
+
dataknobs_bots/memory/base.py,sha256=7iG1JN3mqqaDAptJKJgfuHIQy6gh6qRmsVYBF1ow5xI,1000
|
|
22
|
+
dataknobs_bots/memory/buffer.py,sha256=LI65dxa9EI3WthsSqT6vFVz4CwUXsDdVgRykUUt6Fw8,1759
|
|
23
|
+
dataknobs_bots/memory/vector.py,sha256=8pr2EZSCjiG_dgKslHewAtLw0xeftcf6vSYVoUIvO1E,6768
|
|
24
|
+
dataknobs_bots/middleware/__init__.py,sha256=L705nKGPw9aHTEWHh2-j4gcmfR-oZa60BVzJA_dTEHU,262
|
|
25
|
+
dataknobs_bots/middleware/base.py,sha256=pVfoRIxpcjrIWsDtQjJVBNBLoIbtNUg44Gl4wThbBMc,3027
|
|
26
|
+
dataknobs_bots/middleware/cost.py,sha256=3QYet98p_3g8DDbCXtSBh9Zad0X-2lqdjRB2Y0qdmlg,14520
|
|
27
|
+
dataknobs_bots/middleware/logging.py,sha256=SyDEaO_8TrebMRZ58imrBgGRp8XYqoX1npvgiWYwMho,6303
|
|
28
|
+
dataknobs_bots/reasoning/__init__.py,sha256=TIl2Ny2tmDk0DuELSaro-PI8bbIurlE6w3h3y-1Y70g,1881
|
|
29
|
+
dataknobs_bots/reasoning/base.py,sha256=y51YacVhCZzNB2j3qr7E0u-6cm94EiiM2k5QpYBLeAs,1407
|
|
30
|
+
dataknobs_bots/reasoning/react.py,sha256=5iU8KKLXA-ytjEEDvP_opgp0E1WyLGlDON7jVtFsVAQ,10249
|
|
31
|
+
dataknobs_bots/reasoning/simple.py,sha256=TtF5Sf8qc_7G4R-nFTEhRaRkMyblK1B4135a6UtCWCU,1457
|
|
32
|
+
dataknobs_bots/registry/__init__.py,sha256=lvZ5DcsKtpNWT2qBdRL9gyR89ZsItgXrHON6ZWAVRvk,1039
|
|
33
|
+
dataknobs_bots/registry/backend.py,sha256=9Li1eMc_Z9pacSnj4F7tPlJLtSyNTbYFNtPyCusDcb4,4693
|
|
34
|
+
dataknobs_bots/registry/memory.py,sha256=ADwYje7wALmjPVL596zTXjaXKG2Nm1vsrtuBblo0nOc,7097
|
|
35
|
+
dataknobs_bots/registry/models.py,sha256=lYHUqvSvN7_jbJBKNWUyllEhO_B8LKbrqYruz8KHtUk,3370
|
|
36
|
+
dataknobs_bots/registry/portability.py,sha256=BnYjayDQhHZcoBxOQrsMi4yfWF7Jkt5Pqz6azeOor8w,6554
|
|
37
|
+
dataknobs_bots/tools/__init__.py,sha256=Gmj8Nek0BJZ0vRnPL01bBlgaX9WW2oxhhgBKCHW2WrM,111
|
|
38
|
+
dataknobs_bots/tools/knowledge_search.py,sha256=wBo5wJ3s3kOUoWKyECNxWaCuvqy3BMtgQ6j0DZTk1LA,3505
|
|
39
|
+
dataknobs_bots/utils/__init__.py,sha256=n8CLFPBgKbuHmPMc5-yioYScNXpM5a8JtRt-sJawDjs,68
|
|
40
|
+
dataknobs_bots-0.2.4.dist-info/METADATA,sha256=0IxJUWdG_skKG0wSu6xufuZg_yDW-NN37EmmsmKC5vo,15373
|
|
41
|
+
dataknobs_bots-0.2.4.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
42
|
+
dataknobs_bots-0.2.4.dist-info/RECORD,,
|