neurostack-org 1.0.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.
- neurostack_org-1.0.0/PKG-INFO +322 -0
- neurostack_org-1.0.0/README.md +0 -0
- neurostack_org-1.0.0/pyproject.toml +66 -0
- neurostack_org-1.0.0/setup.cfg +4 -0
- neurostack_org-1.0.0/src/brain/__init__.py +0 -0
- neurostack_org-1.0.0/src/brain/config/__init__.py +0 -0
- neurostack_org-1.0.0/src/brain/config/brain_config.py +75 -0
- neurostack_org-1.0.0/src/brain/config/confidence_config.py +79 -0
- neurostack_org-1.0.0/src/brain/config/persona_config.py +50 -0
- neurostack_org-1.0.0/src/brain/config/retrieval_config.py +23 -0
- neurostack_org-1.0.0/src/brain/core/__init__.py +21 -0
- neurostack_org-1.0.0/src/brain/core/input_validator.py +164 -0
- neurostack_org-1.0.0/src/brain/core/intent_classifier.py +273 -0
- neurostack_org-1.0.0/src/brain/core/knowledge_retriever.py +284 -0
- neurostack_org-1.0.0/src/brain/core/orchestrator.py +257 -0
- neurostack_org-1.0.0/src/brain/core/reasoning_engine.py +411 -0
- neurostack_org-1.0.0/src/brain/core/response_formatter.py +294 -0
- neurostack_org-1.0.0/src/brain/factory.py +151 -0
- neurostack_org-1.0.0/src/brain/interfaces/__init__.py +0 -0
- neurostack_org-1.0.0/src/brain/interfaces/embedding.py +38 -0
- neurostack_org-1.0.0/src/brain/interfaces/llm.py +51 -0
- neurostack_org-1.0.0/src/brain/interfaces/vector_store.py +45 -0
- neurostack_org-1.0.0/src/brain/logging/__init__.py +0 -0
- neurostack_org-1.0.0/src/brain/logging/formatters.py +35 -0
- neurostack_org-1.0.0/src/brain/logging/logger.py +91 -0
- neurostack_org-1.0.0/src/brain/logging/trace.py +97 -0
- neurostack_org-1.0.0/src/brain/models/__init__.py +0 -0
- neurostack_org-1.0.0/src/brain/models/confidence.py +20 -0
- neurostack_org-1.0.0/src/brain/models/intent.py +47 -0
- neurostack_org-1.0.0/src/brain/models/persona.py +37 -0
- neurostack_org-1.0.0/src/brain/models/request.py +60 -0
- neurostack_org-1.0.0/src/brain/models/response.py +111 -0
- neurostack_org-1.0.0/src/brain/models/retrieval.py +32 -0
- neurostack_org-1.0.0/src/brain/prompts/__init__.py +0 -0
- neurostack_org-1.0.0/src/brain/prompts/base.py +130 -0
- neurostack_org-1.0.0/src/brain/prompts/intent_classifier.py +89 -0
- neurostack_org-1.0.0/src/brain/prompts/reasoning/__init__.py +35 -0
- neurostack_org-1.0.0/src/brain/prompts/reasoning/action.py +37 -0
- neurostack_org-1.0.0/src/brain/prompts/reasoning/decision_recall.py +26 -0
- neurostack_org-1.0.0/src/brain/prompts/reasoning/informational.py +33 -0
- neurostack_org-1.0.0/src/brain/prompts/reasoning/metrics.py +32 -0
- neurostack_org-1.0.0/src/brain/prompts/reasoning/planning.py +27 -0
- neurostack_org-1.0.0/src/brain/prompts/reasoning/status.py +27 -0
- neurostack_org-1.0.0/src/brain/prompts/reasoning/summary.py +27 -0
- neurostack_org-1.0.0/src/brain/utils/__init__.py +0 -0
- neurostack_org-1.0.0/src/brain/utils/confidence.py +208 -0
- neurostack_org-1.0.0/src/brain/utils/ranking.py +188 -0
- neurostack_org-1.0.0/src/brain/utils/time.py +148 -0
- neurostack_org-1.0.0/src/brain/utils/validation.py +166 -0
- neurostack_org-1.0.0/src/brain/utils/visibility.py +18 -0
- neurostack_org-1.0.0/src/clients/__init__.py +18 -0
- neurostack_org-1.0.0/src/clients/anthropic_client.py +0 -0
- neurostack_org-1.0.0/src/clients/anthropic_llm.py +97 -0
- neurostack_org-1.0.0/src/clients/azure_openai_llm.py +35 -0
- neurostack_org-1.0.0/src/clients/example_vector_client.py +0 -0
- neurostack_org-1.0.0/src/clients/mock_embedding.py +125 -0
- neurostack_org-1.0.0/src/clients/mock_vector_store.py +187 -0
- neurostack_org-1.0.0/src/neurostack/license.py +237 -0
- neurostack_org-1.0.0/src/neurostack/logging.py +22 -0
- neurostack_org-1.0.0/src/neurostack/models/__init__.py +40 -0
- neurostack_org-1.0.0/src/neurostack/models/context.py +33 -0
- neurostack_org-1.0.0/src/neurostack/models/knowledge.py +61 -0
- neurostack_org-1.0.0/src/neurostack/models/permission.py +119 -0
- neurostack_org-1.0.0/src/neurostack_org.egg-info/PKG-INFO +322 -0
- neurostack_org-1.0.0/src/neurostack_org.egg-info/SOURCES.txt +150 -0
- neurostack_org-1.0.0/src/neurostack_org.egg-info/dependency_links.txt +1 -0
- neurostack_org-1.0.0/src/neurostack_org.egg-info/entry_points.txt +2 -0
- neurostack_org-1.0.0/src/neurostack_org.egg-info/requires.txt +31 -0
- neurostack_org-1.0.0/src/neurostack_org.egg-info/top_level.txt +4 -0
- neurostack_org-1.0.0/src/pipeline/__init__.py +0 -0
- neurostack_org-1.0.0/src/pipeline/audit/__init__.py +0 -0
- neurostack_org-1.0.0/src/pipeline/audit/lineage.py +0 -0
- neurostack_org-1.0.0/src/pipeline/audit/logger.py +753 -0
- neurostack_org-1.0.0/src/pipeline/audit/metrics.py +0 -0
- neurostack_org-1.0.0/src/pipeline/auth/__init__.py +0 -0
- neurostack_org-1.0.0/src/pipeline/auth/oauth_manager.py +0 -0
- neurostack_org-1.0.0/src/pipeline/auth/permission_sync.py +522 -0
- neurostack_org-1.0.0/src/pipeline/auth/token_store.py +602 -0
- neurostack_org-1.0.0/src/pipeline/cli/__init__.py +0 -0
- neurostack_org-1.0.0/src/pipeline/cli/connector_manage.py +0 -0
- neurostack_org-1.0.0/src/pipeline/cli/ingest.py +0 -0
- neurostack_org-1.0.0/src/pipeline/cli/main.py +192 -0
- neurostack_org-1.0.0/src/pipeline/cli/status.py +0 -0
- neurostack_org-1.0.0/src/pipeline/config/__init__.py +0 -0
- neurostack_org-1.0.0/src/pipeline/config/loader.py +136 -0
- neurostack_org-1.0.0/src/pipeline/config/pipeline_config.py +0 -0
- neurostack_org-1.0.0/src/pipeline/config/storage_config.py +0 -0
- neurostack_org-1.0.0/src/pipeline/connectors/__init__.py +0 -0
- neurostack_org-1.0.0/src/pipeline/connectors/base.py +659 -0
- neurostack_org-1.0.0/src/pipeline/connectors/csv/__init__.py +0 -0
- neurostack_org-1.0.0/src/pipeline/connectors/csv/connector.py +298 -0
- neurostack_org-1.0.0/src/pipeline/connectors/google_workspace/__init__.py +0 -0
- neurostack_org-1.0.0/src/pipeline/connectors/google_workspace/auth.py +235 -0
- neurostack_org-1.0.0/src/pipeline/connectors/google_workspace/calendar_connector.py +0 -0
- neurostack_org-1.0.0/src/pipeline/connectors/google_workspace/docs_connector.py +673 -0
- neurostack_org-1.0.0/src/pipeline/connectors/google_workspace/drive_connector.py +0 -0
- neurostack_org-1.0.0/src/pipeline/connectors/google_workspace/permission_mapper.py +293 -0
- neurostack_org-1.0.0/src/pipeline/connectors/jira/__init__.py +0 -0
- neurostack_org-1.0.0/src/pipeline/connectors/jira/auth.py +0 -0
- neurostack_org-1.0.0/src/pipeline/connectors/jira/config.py +0 -0
- neurostack_org-1.0.0/src/pipeline/connectors/jira/connector.py +612 -0
- neurostack_org-1.0.0/src/pipeline/connectors/jira/permission_mapper.py +224 -0
- neurostack_org-1.0.0/src/pipeline/connectors/registry.py +597 -0
- neurostack_org-1.0.0/src/pipeline/connectors/slack/__init__.py +0 -0
- neurostack_org-1.0.0/src/pipeline/connectors/slack/auth.py +0 -0
- neurostack_org-1.0.0/src/pipeline/connectors/slack/connector.py +1028 -0
- neurostack_org-1.0.0/src/pipeline/connectors/slack/deduplication.py +0 -0
- neurostack_org-1.0.0/src/pipeline/connectors/slack/permission_mapper.py +0 -0
- neurostack_org-1.0.0/src/pipeline/core/__init__.py +0 -0
- neurostack_org-1.0.0/src/pipeline/core/chunker.py +0 -0
- neurostack_org-1.0.0/src/pipeline/core/ingestion_engine.py +786 -0
- neurostack_org-1.0.0/src/pipeline/core/live_data_handler.py +0 -0
- neurostack_org-1.0.0/src/pipeline/core/orchestrator.py +936 -0
- neurostack_org-1.0.0/src/pipeline/core/permission_engine.py +0 -0
- neurostack_org-1.0.0/src/pipeline/models/__init__.py +4 -0
- neurostack_org-1.0.0/src/pipeline/models/connector_config.py +0 -0
- neurostack_org-1.0.0/src/pipeline/models/ingestion_job.py +0 -0
- neurostack_org-1.0.0/src/pipeline/models/storage.py +0 -0
- neurostack_org-1.0.0/src/pipeline/processing/__init__.py +0 -0
- neurostack_org-1.0.0/src/pipeline/processing/chunking/__init__.py +0 -0
- neurostack_org-1.0.0/src/pipeline/processing/chunking/document_chunker.py +942 -0
- neurostack_org-1.0.0/src/pipeline/processing/chunking/semantic_chunker.py +0 -0
- neurostack_org-1.0.0/src/pipeline/processing/chunking/structured_chunker.py +0 -0
- neurostack_org-1.0.0/src/pipeline/processing/embeddings/__init__.py +0 -0
- neurostack_org-1.0.0/src/pipeline/processing/embeddings/embedding_client.py +776 -0
- neurostack_org-1.0.0/src/pipeline/processing/embeddings/mock_embeddings.py +759 -0
- neurostack_org-1.0.0/src/pipeline/processing/embeddings/openai_embeddings.py +687 -0
- neurostack_org-1.0.0/src/pipeline/processing/normalizer.py +834 -0
- neurostack_org-1.0.0/src/pipeline/processing/versioning.py +0 -0
- neurostack_org-1.0.0/src/pipeline/scheduling/__init__.py +0 -0
- neurostack_org-1.0.0/src/pipeline/scheduling/checkpoint.py +0 -0
- neurostack_org-1.0.0/src/pipeline/scheduling/job_queue.py +0 -0
- neurostack_org-1.0.0/src/pipeline/scheduling/rate_limiter.py +0 -0
- neurostack_org-1.0.0/src/pipeline/scheduling/scheduler.py +0 -0
- neurostack_org-1.0.0/src/pipeline/storage/__init__.py +0 -0
- neurostack_org-1.0.0/src/pipeline/storage/graph/__init__.py +0 -0
- neurostack_org-1.0.0/src/pipeline/storage/graph/neo4j_store.py +0 -0
- neurostack_org-1.0.0/src/pipeline/storage/interfaces.py +699 -0
- neurostack_org-1.0.0/src/pipeline/storage/metadata/__init__.py +0 -0
- neurostack_org-1.0.0/src/pipeline/storage/metadata/postgres.py +1290 -0
- neurostack_org-1.0.0/src/pipeline/storage/migrations/env.py +84 -0
- neurostack_org-1.0.0/src/pipeline/storage/migrations/versions/f2816fb07a30_initial_schema.py +193 -0
- neurostack_org-1.0.0/src/pipeline/storage/semantic/__init__.py +1 -0
- neurostack_org-1.0.0/src/pipeline/storage/semantic/mock_store.py +1045 -0
- neurostack_org-1.0.0/src/pipeline/storage/semantic/pinecone_store.py +895 -0
- neurostack_org-1.0.0/src/pipeline/storage/semantic/qdrant_store.py +728 -0
- neurostack_org-1.0.0/src/pipeline/storage/semantic/weaviate_store.py +0 -0
- neurostack_org-1.0.0/src/pipeline/utils/__init__.py +0 -0
- neurostack_org-1.0.0/src/pipeline/utils/deduplication.py +666 -0
- neurostack_org-1.0.0/src/pipeline/utils/exceptions.py +0 -0
- neurostack_org-1.0.0/src/pipeline/utils/retry.py +636 -0
- neurostack_org-1.0.0/src/pipeline/utils/validation.py +0 -0
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: neurostack-org
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Enterprise AI SDK — permission-enforced knowledge retrieval across Jira, Slack, Google Docs
|
|
5
|
+
Author: Tauseeq Kazi
|
|
6
|
+
License: BSL-1.1
|
|
7
|
+
Requires-Python: >=3.11
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
Requires-Dist: anthropic>=0.40.0
|
|
10
|
+
Requires-Dist: openai>=1.30.0
|
|
11
|
+
Requires-Dist: pydantic>=2.0.0
|
|
12
|
+
Requires-Dist: pyyaml>=6.0
|
|
13
|
+
Requires-Dist: alembic>=1.13.0
|
|
14
|
+
Requires-Dist: psycopg2-binary>=2.9.0
|
|
15
|
+
Requires-Dist: click>=8.1.0
|
|
16
|
+
Requires-Dist: rich>=13.0.0
|
|
17
|
+
Requires-Dist: httpx>=0.25.0
|
|
18
|
+
Provides-Extra: dev
|
|
19
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
20
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
21
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
|
|
22
|
+
Requires-Dist: black>=24.0.0; extra == "dev"
|
|
23
|
+
Requires-Dist: mypy>=1.8.0; extra == "dev"
|
|
24
|
+
Requires-Dist: ruff>=0.2.0; extra == "dev"
|
|
25
|
+
Provides-Extra: qdrant
|
|
26
|
+
Requires-Dist: qdrant-client>=1.7.0; extra == "qdrant"
|
|
27
|
+
Provides-Extra: pinecone
|
|
28
|
+
Requires-Dist: pinecone-client>=3.0.0; extra == "pinecone"
|
|
29
|
+
Provides-Extra: google
|
|
30
|
+
Requires-Dist: google-auth>=2.0.0; extra == "google"
|
|
31
|
+
Requires-Dist: google-auth-oauthlib>=1.0.0; extra == "google"
|
|
32
|
+
Requires-Dist: google-api-python-client>=2.80.0; extra == "google"
|
|
33
|
+
Provides-Extra: encryption
|
|
34
|
+
Requires-Dist: cryptography>=41.0.0; extra == "encryption"
|
|
35
|
+
|
|
36
|
+
# Neurostack Brain
|
|
37
|
+
|
|
38
|
+
**Enterprise AI Intelligence Brain**
|
|
39
|
+
|
|
40
|
+
Neurostack is an AI intelligence layer designed to sit on top of a company's existing systems and make them easier to understand, query, and reason about.
|
|
41
|
+
|
|
42
|
+
## 🎯 What Is Neurostack?
|
|
43
|
+
|
|
44
|
+
Neurostack is **not** a chatbot, project management tool, or workflow automation platform.
|
|
45
|
+
|
|
46
|
+
Neurostack is an **AI Brain** that:
|
|
47
|
+
|
|
48
|
+
- Reasons over company knowledge (documents, meetings, tasks, decisions)
|
|
49
|
+
- Provides accurate, contextual answers
|
|
50
|
+
- Respects persona-based access control (employee vs manager)
|
|
51
|
+
- Handles uncertainty gracefully
|
|
52
|
+
- Operates at enterprise scale
|
|
53
|
+
|
|
54
|
+
## 🏗️ Architecture
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
┌─────────────────────────────────────────────────────────┐
|
|
58
|
+
│ Brain Pipeline │
|
|
59
|
+
│ │
|
|
60
|
+
│ Input → Validate → Classify → Retrieve → Reason → Format │
|
|
61
|
+
│ (Stage 1) (Stage 2) (Stage 3) (Stage 4) (Stage 5) │
|
|
62
|
+
└─────────────────────────────────────────────────────────┘
|
|
63
|
+
|
|
64
|
+
Key Properties:
|
|
65
|
+
- 2 LLM calls per query (classify + reason)
|
|
66
|
+
- Single-pass, deterministic execution
|
|
67
|
+
- Batch-friendly, rate-limited safe
|
|
68
|
+
- Full audit trail via tracing
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**Core Components:**
|
|
72
|
+
|
|
73
|
+
1. **InputValidator** - Validates and normalizes requests
|
|
74
|
+
2. **IntentClassifier** - Classifies user intent (9 types)
|
|
75
|
+
3. **KnowledgeRetriever** - Retrieves from RAG + live context
|
|
76
|
+
4. **ReasoningEngine** - Generates answers with LLM
|
|
77
|
+
5. **ResponseFormatter** - Formats final output
|
|
78
|
+
6. **BrainOrchestrator** - Coordinates full pipeline
|
|
79
|
+
|
|
80
|
+
See [ARCHITECTURE.md](docs/architecture.md) for detailed design.
|
|
81
|
+
|
|
82
|
+
## 🚀 Quick Start
|
|
83
|
+
|
|
84
|
+
### Installation
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
# Clone repository
|
|
88
|
+
git clone https://github.com/your-org/neurostack-brain.git
|
|
89
|
+
cd neurostack-brain
|
|
90
|
+
|
|
91
|
+
# Install dependencies
|
|
92
|
+
pip install -r requirements.txt
|
|
93
|
+
|
|
94
|
+
# Set up environment
|
|
95
|
+
export ANTHROPIC_API_KEY="your-api-key"
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Basic Usage
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
from brain.factory import BrainFactory
|
|
102
|
+
from clients.anthropic_llm import AnthropicLLMClient
|
|
103
|
+
from clients.mock_vector_store import MockVectorStore
|
|
104
|
+
from clients.mock_embedding import SimpleEmbeddingClient
|
|
105
|
+
|
|
106
|
+
# Initialize clients
|
|
107
|
+
llm_client = AnthropicLLMClient(api_key="your-key")
|
|
108
|
+
vector_store = MockVectorStore()
|
|
109
|
+
embedding_client = SimpleEmbeddingClient(dimension=768)
|
|
110
|
+
|
|
111
|
+
# Create brain
|
|
112
|
+
brain = BrainFactory.create_brain(
|
|
113
|
+
llm_client=llm_client,
|
|
114
|
+
vector_store=vector_store,
|
|
115
|
+
embedding_client=embedding_client
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
# Process query
|
|
119
|
+
response = brain.process({
|
|
120
|
+
"query": {
|
|
121
|
+
"user_input": "What is our refund policy?"
|
|
122
|
+
},
|
|
123
|
+
"context": {
|
|
124
|
+
"tenant_id": "company_a",
|
|
125
|
+
"persona": "employee",
|
|
126
|
+
"user_id": "alice@company.com"
|
|
127
|
+
},
|
|
128
|
+
"conversation_history": [],
|
|
129
|
+
"live_context": {},
|
|
130
|
+
"options": {}
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
print(f"Answer: {response.answer.content}")
|
|
134
|
+
print(f"Confidence: {response.answer.confidence.value}")
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
See [examples/](examples/) for more usage patterns.
|
|
138
|
+
|
|
139
|
+
## 📋 Features
|
|
140
|
+
|
|
141
|
+
### ✅ Knowledge Types
|
|
142
|
+
|
|
143
|
+
- Documents (policies, SOPs, manuals)
|
|
144
|
+
- Tasks (work items, tickets)
|
|
145
|
+
- Meetings (decisions, action items)
|
|
146
|
+
- Decisions (finalized outcomes)
|
|
147
|
+
- Metrics (KPIs, analytics)
|
|
148
|
+
- Events (changes, incidents)
|
|
149
|
+
- Facts (distilled truths)
|
|
150
|
+
|
|
151
|
+
### ✅ Intent Classification
|
|
152
|
+
|
|
153
|
+
- Informational queries
|
|
154
|
+
- Status queries
|
|
155
|
+
- Metrics queries
|
|
156
|
+
- Summary requests
|
|
157
|
+
- Planning requests
|
|
158
|
+
- Task actions
|
|
159
|
+
- Decision recall
|
|
160
|
+
- Out-of-scope detection
|
|
161
|
+
|
|
162
|
+
### ✅ Persona-Based Access Control
|
|
163
|
+
|
|
164
|
+
- **Employee**: Personal tasks, public docs
|
|
165
|
+
- **Manager**: Team analytics, multi-person visibility
|
|
166
|
+
- Automatic scope enforcement
|
|
167
|
+
- Graceful refusal with suggestions
|
|
168
|
+
|
|
169
|
+
### ✅ Confidence & Uncertainty
|
|
170
|
+
|
|
171
|
+
- 3-level confidence model (retrieval, answer, action)
|
|
172
|
+
- Conflict detection
|
|
173
|
+
- Staleness warnings
|
|
174
|
+
- Source attribution
|
|
175
|
+
- Reasoning transparency
|
|
176
|
+
|
|
177
|
+
### ✅ Memory Architecture
|
|
178
|
+
|
|
179
|
+
- **Short-term**: Conversation context (ephemeral)
|
|
180
|
+
- **Long-term**: RAG/vector store (persistent)
|
|
181
|
+
- **Live context**: Current state (injected)
|
|
182
|
+
|
|
183
|
+
## 🧪 Testing
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
# Run all tests
|
|
187
|
+
pytest tests/
|
|
188
|
+
|
|
189
|
+
# Run with coverage
|
|
190
|
+
pytest --cov=brain --cov-report=html tests/
|
|
191
|
+
|
|
192
|
+
# Run specific category
|
|
193
|
+
pytest tests/unit/ # Unit tests
|
|
194
|
+
pytest tests/integration/ # Integration tests
|
|
195
|
+
pytest tests/evaluation/ # Evaluation tests
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
**Test Coverage:**
|
|
199
|
+
|
|
200
|
+
- Unit tests: ~15 tests
|
|
201
|
+
- Integration tests: ~12 tests
|
|
202
|
+
- Evaluation tests: ~1 test
|
|
203
|
+
- Total: **~28 comprehensive tests**
|
|
204
|
+
|
|
205
|
+
See [tests/README.md](tests/README.md) for testing guide.
|
|
206
|
+
|
|
207
|
+
## 📚 Documentation
|
|
208
|
+
|
|
209
|
+
- [ARCHITECTURE.md](docs/architecture.md) - System design & components
|
|
210
|
+
- [API_REFERENCE.md](docs/api_reference.md) - Component APIs
|
|
211
|
+
- [USAGE_GUIDE.md](docs/usage_guide.md) - How to use the brain
|
|
212
|
+
- [EVALUATION.md](docs/evaluation.md) - Quality metrics & calibration
|
|
213
|
+
|
|
214
|
+
## 🔧 Configuration
|
|
215
|
+
|
|
216
|
+
```python
|
|
217
|
+
from brain.config.brain_config import BrainConfig, LLMSettings
|
|
218
|
+
from brain.config.retrieval_config import RetrieverConfig
|
|
219
|
+
|
|
220
|
+
config = BrainConfig(
|
|
221
|
+
llm=LLMSettings(
|
|
222
|
+
model="claude-sonnet-4-20250514",
|
|
223
|
+
temperature=0.0,
|
|
224
|
+
max_tokens=1500
|
|
225
|
+
),
|
|
226
|
+
retrieval=RetrieverConfig(
|
|
227
|
+
default_top_k=10,
|
|
228
|
+
strong_threshold=0.80
|
|
229
|
+
)
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
brain = BrainFactory.create_brain(
|
|
233
|
+
llm_client=llm_client,
|
|
234
|
+
vector_store=vector_store,
|
|
235
|
+
embedding_client=embedding_client,
|
|
236
|
+
config=config # Custom config
|
|
237
|
+
)
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
All thresholds and parameters are configurable via dataclasses or YAML.
|
|
241
|
+
|
|
242
|
+
## 🏢 Production Considerations
|
|
243
|
+
|
|
244
|
+
### Required External Services
|
|
245
|
+
|
|
246
|
+
1. **LLM Client** - Claude API (or compatible)
|
|
247
|
+
2. **Vector Store** - Pinecone, Weaviate, Qdrant, etc.
|
|
248
|
+
3. **Embedding Client** - OpenAI, Cohere, etc.
|
|
249
|
+
|
|
250
|
+
### Recommended Infrastructure
|
|
251
|
+
|
|
252
|
+
- **Async Job Queue** - For heavy analysis (Celery, RQ)
|
|
253
|
+
- **Cache Layer** - For embeddings and retrieval (Redis)
|
|
254
|
+
- **Trace Storage** - For audit trail (PostgreSQL, Elasticsearch)
|
|
255
|
+
- **Rate Limiting** - External rate limiter (not in brain)
|
|
256
|
+
|
|
257
|
+
### Performance Characteristics
|
|
258
|
+
|
|
259
|
+
- **Latency**: ~2-5 seconds per query (2 LLM calls)
|
|
260
|
+
- **Throughput**: Rate-limited by LLM provider
|
|
261
|
+
- **Memory**: ~100-500 MB per brain instance
|
|
262
|
+
- **Scalability**: Stateless, horizontally scalable
|
|
263
|
+
|
|
264
|
+
## 🛡️ Design Principles
|
|
265
|
+
|
|
266
|
+
1. **Intelligence over automation** - Understanding before action
|
|
267
|
+
2. **Reasoning over retrieval** - Explaining vs fetching
|
|
268
|
+
3. **Trust over cleverness** - Predictable, cautious answers
|
|
269
|
+
4. **Abstraction over tools** - Works regardless of backend systems
|
|
270
|
+
5. **Incremental adoption** - Provides value with partial data
|
|
271
|
+
|
|
272
|
+
## 📊 Status
|
|
273
|
+
|
|
274
|
+
**Current Phase:** Early validation (tested with ~500 users across multiple companies)
|
|
275
|
+
|
|
276
|
+
**Production Readiness:**
|
|
277
|
+
|
|
278
|
+
- ✅ Core pipeline complete
|
|
279
|
+
- ✅ Comprehensive test suite
|
|
280
|
+
- ✅ Persona enforcement
|
|
281
|
+
- ✅ Error handling
|
|
282
|
+
- ⚠️ Async job support (basic implementation)
|
|
283
|
+
- ⚠️ Caching layer (deferred)
|
|
284
|
+
- ⚠️ Distributed tracing (basic implementation)
|
|
285
|
+
|
|
286
|
+
## 🤝 Contributing
|
|
287
|
+
|
|
288
|
+
Contributions are welcome! Please read our [CONTRIBUTING.md](CONTRIBUTING.md) first.
|
|
289
|
+
|
|
290
|
+
### Development Setup
|
|
291
|
+
|
|
292
|
+
```bash
|
|
293
|
+
# Install dev dependencies
|
|
294
|
+
pip install -e ".[dev]"
|
|
295
|
+
|
|
296
|
+
# Run tests
|
|
297
|
+
pytest tests/
|
|
298
|
+
|
|
299
|
+
# Run linting
|
|
300
|
+
black src/ tests/
|
|
301
|
+
mypy src/
|
|
302
|
+
ruff check src/
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
## 📝 License
|
|
306
|
+
|
|
307
|
+
[Your License Here]
|
|
308
|
+
|
|
309
|
+
## 🙏 Acknowledgments
|
|
310
|
+
|
|
311
|
+
Built with:
|
|
312
|
+
|
|
313
|
+
- [Anthropic Claude](https://anthropic.com) - LLM reasoning
|
|
314
|
+
- [Pydantic](https://pydantic.dev) - Data validation
|
|
315
|
+
- [pytest](https://pytest.org) - Testing framework
|
|
316
|
+
|
|
317
|
+
---
|
|
318
|
+
|
|
319
|
+
**Neurostack** - Making enterprise knowledge intelligently accessible.
|
|
320
|
+
fix
|
|
321
|
+
|
|
322
|
+
|
|
Binary file
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "neurostack-org"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Enterprise AI SDK — permission-enforced knowledge retrieval across Jira, Slack, Google Docs"
|
|
9
|
+
authors = [{name = "Tauseeq Kazi"}]
|
|
10
|
+
license = {text = "BSL-1.1"}
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
requires-python = ">=3.11"
|
|
13
|
+
|
|
14
|
+
dependencies = [
|
|
15
|
+
"anthropic>=0.40.0",
|
|
16
|
+
"openai>=1.30.0",
|
|
17
|
+
"pydantic>=2.0.0",
|
|
18
|
+
"pyyaml>=6.0",
|
|
19
|
+
"alembic>=1.13.0",
|
|
20
|
+
"psycopg2-binary>=2.9.0",
|
|
21
|
+
"click>=8.1.0",
|
|
22
|
+
"rich>=13.0.0",
|
|
23
|
+
"httpx>=0.25.0",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.scripts]
|
|
27
|
+
neurostack = "pipeline.cli.main:cli"
|
|
28
|
+
|
|
29
|
+
[project.optional-dependencies]
|
|
30
|
+
dev = [
|
|
31
|
+
"pytest>=8.0.0",
|
|
32
|
+
"pytest-cov>=4.0.0",
|
|
33
|
+
"pytest-asyncio>=0.23.0",
|
|
34
|
+
"black>=24.0.0",
|
|
35
|
+
"mypy>=1.8.0",
|
|
36
|
+
"ruff>=0.2.0",
|
|
37
|
+
]
|
|
38
|
+
qdrant = ["qdrant-client>=1.7.0"]
|
|
39
|
+
pinecone = ["pinecone-client>=3.0.0"]
|
|
40
|
+
google = [
|
|
41
|
+
"google-auth>=2.0.0",
|
|
42
|
+
"google-auth-oauthlib>=1.0.0",
|
|
43
|
+
"google-api-python-client>=2.80.0",
|
|
44
|
+
]
|
|
45
|
+
encryption = ["cryptography>=41.0.0"]
|
|
46
|
+
|
|
47
|
+
# 🔑 THIS MAKES `brain` IMPORTABLE
|
|
48
|
+
[tool.setuptools]
|
|
49
|
+
package-dir = {"" = "src"}
|
|
50
|
+
|
|
51
|
+
[tool.setuptools.packages.find]
|
|
52
|
+
where = ["src"]
|
|
53
|
+
|
|
54
|
+
# Tooling
|
|
55
|
+
[tool.pytest.ini_options]
|
|
56
|
+
testpaths = ["tests"]
|
|
57
|
+
|
|
58
|
+
[tool.black]
|
|
59
|
+
line-length = 100
|
|
60
|
+
target-version = ["py311"]
|
|
61
|
+
|
|
62
|
+
[tool.mypy]
|
|
63
|
+
python_version = "3.11"
|
|
64
|
+
strict = true
|
|
65
|
+
warn_return_any = true
|
|
66
|
+
warn_unused_configs = true
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Main brain configuration.
|
|
3
|
+
|
|
4
|
+
Dataclasses are source of truth. YAML loading is optional convenience.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from dataclasses import dataclass, field
|
|
8
|
+
from typing import Dict, Optional
|
|
9
|
+
import yaml
|
|
10
|
+
|
|
11
|
+
from .retrieval_config import RetrieverConfig
|
|
12
|
+
from .confidence_config import ConfidenceConfig
|
|
13
|
+
from .persona_config import PersonaConfig
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@dataclass
|
|
17
|
+
class LLMSettings:
|
|
18
|
+
"""LLM client settings"""
|
|
19
|
+
model: str = "claude-sonnet-4-20250514"
|
|
20
|
+
temperature: float = 0.0
|
|
21
|
+
max_tokens: int = 1000
|
|
22
|
+
timeout_seconds: int = 30
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@dataclass
|
|
26
|
+
class ConversationSettings:
|
|
27
|
+
"""Conversation management settings"""
|
|
28
|
+
max_history_turns: int = 5 # Last N turns to include
|
|
29
|
+
max_history_tokens: int = 2000 # Approximate token budget for history
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@dataclass
|
|
35
|
+
class BrainConfig:
|
|
36
|
+
"""
|
|
37
|
+
Main brain configuration.
|
|
38
|
+
|
|
39
|
+
All components receive config from this root object.
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
# Component configs
|
|
43
|
+
llm: LLMSettings = field(default_factory=LLMSettings)
|
|
44
|
+
retrieval: RetrieverConfig = field(default_factory=RetrieverConfig)
|
|
45
|
+
confidence: ConfidenceConfig = field(default_factory=ConfidenceConfig)
|
|
46
|
+
persona: PersonaConfig = field(default_factory=PersonaConfig)
|
|
47
|
+
conversation: ConversationSettings = field(default_factory=ConversationSettings)
|
|
48
|
+
|
|
49
|
+
@classmethod
|
|
50
|
+
def default(cls) -> "BrainConfig":
|
|
51
|
+
"""Create config with all defaults"""
|
|
52
|
+
return cls()
|
|
53
|
+
|
|
54
|
+
@classmethod
|
|
55
|
+
def from_yaml(cls, path: str) -> "BrainConfig":
|
|
56
|
+
"""
|
|
57
|
+
Load config from YAML file.
|
|
58
|
+
|
|
59
|
+
YAML structure should mirror dataclass hierarchy.
|
|
60
|
+
"""
|
|
61
|
+
with open(path, 'r') as f:
|
|
62
|
+
data = yaml.safe_load(f)
|
|
63
|
+
|
|
64
|
+
return cls(
|
|
65
|
+
llm=LLMSettings(**data.get('llm', {})),
|
|
66
|
+
retrieval=RetrieverConfig.from_dict(data.get('retrieval', {})),
|
|
67
|
+
confidence=ConfidenceConfig.from_dict(data.get('confidence', {})),
|
|
68
|
+
persona=PersonaConfig.from_dict(data.get('persona', {})),
|
|
69
|
+
conversation=ConversationSettings(**data.get('conversation', {}))
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
def to_yaml(self, path: str) -> None:
|
|
73
|
+
"""Export config to YAML file"""
|
|
74
|
+
# Implementation for config export
|
|
75
|
+
pass
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Confidence assessment configuration.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from typing import Dict
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@dataclass
|
|
10
|
+
class ActionConfidenceThresholds:
|
|
11
|
+
"""Confidence thresholds per action type (risk-adjusted)"""
|
|
12
|
+
|
|
13
|
+
# Low risk actions (can execute without confirmation)
|
|
14
|
+
low_risk_threshold: float = 0.85
|
|
15
|
+
low_risk_actions: list = field(default_factory=lambda: [
|
|
16
|
+
"assign_task",
|
|
17
|
+
"add_comment",
|
|
18
|
+
"update_description"
|
|
19
|
+
])
|
|
20
|
+
|
|
21
|
+
# Medium risk actions (require confirmation)
|
|
22
|
+
medium_risk_threshold: float = 0.90
|
|
23
|
+
medium_risk_actions: list = field(default_factory=lambda: [
|
|
24
|
+
"update_status",
|
|
25
|
+
"change_priority",
|
|
26
|
+
"reassign_task"
|
|
27
|
+
])
|
|
28
|
+
|
|
29
|
+
# High risk actions (require strong confirmation)
|
|
30
|
+
high_risk_threshold: float = 0.95
|
|
31
|
+
high_risk_actions: list = field(default_factory=lambda: [
|
|
32
|
+
"delete_task",
|
|
33
|
+
"archive_project",
|
|
34
|
+
"remove_user"
|
|
35
|
+
])
|
|
36
|
+
|
|
37
|
+
def get_threshold(self, action_type: str) -> float:
|
|
38
|
+
"""Get threshold for specific action type"""
|
|
39
|
+
if action_type in self.low_risk_actions:
|
|
40
|
+
return self.low_risk_threshold
|
|
41
|
+
elif action_type in self.medium_risk_actions:
|
|
42
|
+
return self.medium_risk_threshold
|
|
43
|
+
elif action_type in self.high_risk_actions:
|
|
44
|
+
return self.high_risk_threshold
|
|
45
|
+
else:
|
|
46
|
+
return self.medium_risk_threshold # Default to medium
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@dataclass
|
|
50
|
+
class ConfidenceConfig:
|
|
51
|
+
"""Configuration for confidence assessment"""
|
|
52
|
+
|
|
53
|
+
# Retrieval confidence thresholds
|
|
54
|
+
retrieval_strong_threshold: float = 0.75
|
|
55
|
+
retrieval_acceptable_threshold: float = 0.60
|
|
56
|
+
retrieval_dominance_gap: float = 0.15
|
|
57
|
+
|
|
58
|
+
# Answer confidence rules
|
|
59
|
+
# (These are used in decision matrix logic, not hardcoded thresholds)
|
|
60
|
+
|
|
61
|
+
# Confidence upgrade limits
|
|
62
|
+
max_upgrade_from_clarification: int = 1 # Max levels to upgrade
|
|
63
|
+
|
|
64
|
+
# Action confidence
|
|
65
|
+
action_thresholds: ActionConfidenceThresholds = field(
|
|
66
|
+
default_factory=ActionConfidenceThresholds
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
# Conflict handling
|
|
70
|
+
conflict_always_caps_at_uncertain: bool = True
|
|
71
|
+
|
|
72
|
+
@classmethod
|
|
73
|
+
def from_dict(cls, data: dict) -> "ConfidenceConfig":
|
|
74
|
+
"""Create from dictionary"""
|
|
75
|
+
action_data = data.pop('action_thresholds', {})
|
|
76
|
+
return cls(
|
|
77
|
+
action_thresholds=ActionConfidenceThresholds(**action_data),
|
|
78
|
+
**data
|
|
79
|
+
)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Persona configuration and rules.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from typing import Dict, List
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@dataclass
|
|
10
|
+
class PersonaConfig:
|
|
11
|
+
"""Configuration for persona enforcement"""
|
|
12
|
+
|
|
13
|
+
# Employee restrictions
|
|
14
|
+
employee_allowed_scopes: List[str] = field(default_factory=lambda: [
|
|
15
|
+
"personal",
|
|
16
|
+
"public"
|
|
17
|
+
])
|
|
18
|
+
|
|
19
|
+
employee_forbidden_intents: List[str] = field(default_factory=lambda: [
|
|
20
|
+
"metrics_query", # When scope = team
|
|
21
|
+
"planning_request" # When scope = team
|
|
22
|
+
])
|
|
23
|
+
|
|
24
|
+
# Manager permissions
|
|
25
|
+
manager_allowed_scopes: List[str] = field(default_factory=lambda: [
|
|
26
|
+
"personal",
|
|
27
|
+
"public",
|
|
28
|
+
"team"
|
|
29
|
+
])
|
|
30
|
+
|
|
31
|
+
# Ethical constraints (apply to all personas)
|
|
32
|
+
forbidden_query_patterns: List[str] = field(default_factory=lambda: [
|
|
33
|
+
"performance_comparison", # "Who is slower, Alice or Bob?"
|
|
34
|
+
"surveillance_tracking", # "How many hours did X work?"
|
|
35
|
+
"punitive_metrics" # "Show me underperformers"
|
|
36
|
+
])
|
|
37
|
+
|
|
38
|
+
# Scope detection keywords
|
|
39
|
+
team_scope_keywords: List[str] = field(default_factory=lambda: [
|
|
40
|
+
"team", "our", "we", "everyone", "all", "group"
|
|
41
|
+
])
|
|
42
|
+
|
|
43
|
+
personal_scope_keywords: List[str] = field(default_factory=lambda: [
|
|
44
|
+
"my", "I", "me", "mine"
|
|
45
|
+
])
|
|
46
|
+
|
|
47
|
+
@classmethod
|
|
48
|
+
def from_dict(cls, data: dict) -> "PersonaConfig":
|
|
49
|
+
"""Create from dictionary"""
|
|
50
|
+
return cls(**data)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from dataclasses import dataclass, field
|
|
2
|
+
from typing import Dict
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@dataclass
|
|
6
|
+
class RetrieverConfig:
|
|
7
|
+
"""Retrieval configuration"""
|
|
8
|
+
|
|
9
|
+
# Retrieval depth
|
|
10
|
+
default_top_k: int = 5
|
|
11
|
+
max_top_k: int = 20 # hard cap
|
|
12
|
+
|
|
13
|
+
# Confidence thresholds (relative)
|
|
14
|
+
strong_threshold: float = 0.75
|
|
15
|
+
acceptable_threshold: float = 0.60
|
|
16
|
+
dominance_gap: float = 0.15
|
|
17
|
+
recency_boost_factor: float = 0.1
|
|
18
|
+
# Authority weights
|
|
19
|
+
authority_weights: dict = field(default_factory=lambda: {
|
|
20
|
+
"high": 1.2,
|
|
21
|
+
"medium": 1.0,
|
|
22
|
+
"low": 0.8
|
|
23
|
+
})
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Core brain components.
|
|
3
|
+
|
|
4
|
+
These components form the reasoning pipeline.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from .input_validator import InputValidator
|
|
8
|
+
from .intent_classifier import IntentClassifier
|
|
9
|
+
from .knowledge_retriever import KnowledgeRetriever
|
|
10
|
+
from .reasoning_engine import ReasoningEngine
|
|
11
|
+
from .response_formatter import ResponseFormatter
|
|
12
|
+
from .orchestrator import BrainOrchestrator
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
'InputValidator',
|
|
16
|
+
'IntentClassifier',
|
|
17
|
+
'KnowledgeRetriever',
|
|
18
|
+
'ReasoningEngine',
|
|
19
|
+
'ResponseFormatter',
|
|
20
|
+
'BrainOrchestrator',
|
|
21
|
+
]
|