behive 0.1.0__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.
- behive/__init__.py +24 -0
- behive/cli.py +68 -0
- behive/client.py +268 -0
- behive/models.py +93 -0
- behive-0.1.0.dist-info/METADATA +632 -0
- behive-0.1.0.dist-info/RECORD +10 -0
- behive-0.1.0.dist-info/WHEEL +5 -0
- behive-0.1.0.dist-info/entry_points.txt +2 -0
- behive-0.1.0.dist-info/licenses/LICENSE +21 -0
- behive-0.1.0.dist-info/top_level.txt +1 -0
behive/__init__.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""
|
|
2
|
+
BeHive — Research engine that builds structured knowledge graphs.
|
|
3
|
+
|
|
4
|
+
Usage:
|
|
5
|
+
from behive import research
|
|
6
|
+
|
|
7
|
+
result = await research("NVIDIA GPU market 2025", depth=3)
|
|
8
|
+
print(result.claims) # Structured facts with quality scores
|
|
9
|
+
print(result.entities) # Named entities with types
|
|
10
|
+
print(result.report) # Synthesized markdown report
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
__version__ = "0.1.0"
|
|
14
|
+
|
|
15
|
+
from behive.client import research, BeHiveClient
|
|
16
|
+
from behive.models import ResearchResult, Claim, Entity
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"research",
|
|
20
|
+
"BeHiveClient",
|
|
21
|
+
"ResearchResult",
|
|
22
|
+
"Claim",
|
|
23
|
+
"Entity",
|
|
24
|
+
]
|
behive/cli.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"""BeHive CLI — command-line interface for research."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import asyncio
|
|
5
|
+
import sys
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def main():
|
|
9
|
+
parser = argparse.ArgumentParser(
|
|
10
|
+
prog="behive",
|
|
11
|
+
description="BeHive — Research engine that builds structured knowledge graphs"
|
|
12
|
+
)
|
|
13
|
+
subparsers = parser.add_subparsers(dest="command")
|
|
14
|
+
|
|
15
|
+
# research command
|
|
16
|
+
research_p = subparsers.add_parser("research", help="Run a research mission")
|
|
17
|
+
research_p.add_argument("topic", help="Research topic or question")
|
|
18
|
+
research_p.add_argument("-d", "--depth", type=int, default=3, help="Depth 1-5 (default: 3)")
|
|
19
|
+
research_p.add_argument("-s", "--scale", type=int, help="Override task count (30-300)")
|
|
20
|
+
research_p.add_argument("--json", action="store_true", help="Output JSON")
|
|
21
|
+
research_p.add_argument("--no-wait", action="store_true", help="Don't wait for completion")
|
|
22
|
+
|
|
23
|
+
# status command
|
|
24
|
+
status_p = subparsers.add_parser("status", help="Check mission status")
|
|
25
|
+
status_p.add_argument("mission_id", help="Mission ID")
|
|
26
|
+
|
|
27
|
+
# version
|
|
28
|
+
subparsers.add_parser("version", help="Show version")
|
|
29
|
+
|
|
30
|
+
args = parser.parse_args()
|
|
31
|
+
|
|
32
|
+
if args.command == "version":
|
|
33
|
+
from behive import __version__
|
|
34
|
+
print(f"behive {__version__}")
|
|
35
|
+
return
|
|
36
|
+
|
|
37
|
+
if args.command == "research":
|
|
38
|
+
from behive import research
|
|
39
|
+
result = asyncio.run(research(
|
|
40
|
+
args.topic,
|
|
41
|
+
depth=args.depth,
|
|
42
|
+
scale=args.scale,
|
|
43
|
+
wait=not args.no_wait,
|
|
44
|
+
))
|
|
45
|
+
|
|
46
|
+
if args.json:
|
|
47
|
+
import json
|
|
48
|
+
print(json.dumps(result.to_dict(), indent=2, default=str))
|
|
49
|
+
else:
|
|
50
|
+
print(f"\n{'='*60}")
|
|
51
|
+
print(f" BeHive Research: {result.topic}")
|
|
52
|
+
print(f"{'='*60}")
|
|
53
|
+
print(f" Status: {result.status}")
|
|
54
|
+
print(f" {result.summary}")
|
|
55
|
+
print(f"\n Top claims:")
|
|
56
|
+
for claim in result.excellent_claims[:10]:
|
|
57
|
+
print(f" [{claim.quality_score:.2f}] {claim.text[:100]}")
|
|
58
|
+
if result.report:
|
|
59
|
+
print(f"\n Report preview:")
|
|
60
|
+
print(f" {result.report[:500]}")
|
|
61
|
+
print(f"{'='*60}\n")
|
|
62
|
+
return
|
|
63
|
+
|
|
64
|
+
parser.print_help()
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
if __name__ == "__main__":
|
|
68
|
+
main()
|
behive/client.py
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
"""BeHive client — programmatic research interface."""
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
import os
|
|
5
|
+
import time
|
|
6
|
+
from typing import Optional
|
|
7
|
+
|
|
8
|
+
from behive.models import ResearchResult, Claim, Entity
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class BeHiveClient:
|
|
12
|
+
"""
|
|
13
|
+
Client for running research missions.
|
|
14
|
+
|
|
15
|
+
Supports three backends:
|
|
16
|
+
1. Local (direct DB access) — for self-hosted installations
|
|
17
|
+
2. API (remote BeHive server) — for cloud/team usage
|
|
18
|
+
3. MCP (Model Context Protocol) — for AI agent integration
|
|
19
|
+
|
|
20
|
+
Usage:
|
|
21
|
+
client = BeHiveClient() # auto-detects backend
|
|
22
|
+
result = await client.research("topic", depth=3)
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
def __init__(
|
|
26
|
+
self,
|
|
27
|
+
api_url: Optional[str] = None,
|
|
28
|
+
api_key: Optional[str] = None,
|
|
29
|
+
db_url: Optional[str] = None,
|
|
30
|
+
):
|
|
31
|
+
self.api_url = api_url or os.environ.get("BEHIVE_API_URL")
|
|
32
|
+
self.api_key = api_key or os.environ.get("BEHIVE_API_KEY")
|
|
33
|
+
self.db_url = db_url or os.environ.get(
|
|
34
|
+
"BEHIVE_DB_URL",
|
|
35
|
+
"postgresql://hive_app:hive_2026_prod@localhost:5432/hive"
|
|
36
|
+
)
|
|
37
|
+
self._backend = self._detect_backend()
|
|
38
|
+
|
|
39
|
+
def _detect_backend(self) -> str:
|
|
40
|
+
if self.api_url:
|
|
41
|
+
return "api"
|
|
42
|
+
try:
|
|
43
|
+
import psycopg2
|
|
44
|
+
psycopg2.connect(self.db_url).close()
|
|
45
|
+
return "local"
|
|
46
|
+
except Exception:
|
|
47
|
+
pass
|
|
48
|
+
return "api" # fallback
|
|
49
|
+
|
|
50
|
+
async def research(
|
|
51
|
+
self,
|
|
52
|
+
topic: str,
|
|
53
|
+
depth: int = 3,
|
|
54
|
+
scale: Optional[int] = None,
|
|
55
|
+
wait: bool = True,
|
|
56
|
+
timeout: int = 600,
|
|
57
|
+
) -> ResearchResult:
|
|
58
|
+
"""
|
|
59
|
+
Run a research mission.
|
|
60
|
+
|
|
61
|
+
Args:
|
|
62
|
+
topic: Research question or topic
|
|
63
|
+
depth: 1-5 (1=quick scout, 3=standard, 5=deep with falsification)
|
|
64
|
+
scale: Override task count (30-300). Auto-calculated from depth if None.
|
|
65
|
+
wait: Block until done (True) or return immediately (False)
|
|
66
|
+
timeout: Max seconds to wait (default 600s = 10min)
|
|
67
|
+
|
|
68
|
+
Returns:
|
|
69
|
+
ResearchResult with claims, entities, and synthesized report
|
|
70
|
+
"""
|
|
71
|
+
if self._backend == "local":
|
|
72
|
+
return await self._research_local(topic, depth, scale, wait, timeout)
|
|
73
|
+
else:
|
|
74
|
+
return await self._research_api(topic, depth, scale, wait, timeout)
|
|
75
|
+
|
|
76
|
+
async def _research_local(
|
|
77
|
+
self, topic: str, depth: int, scale: Optional[int],
|
|
78
|
+
wait: bool, timeout: int
|
|
79
|
+
) -> ResearchResult:
|
|
80
|
+
"""Run research using local pipeline (direct DB access)."""
|
|
81
|
+
import sys
|
|
82
|
+
sys.path.insert(0, os.environ.get("BEHIVE_PATH", "/home/ubuntu"))
|
|
83
|
+
|
|
84
|
+
from hive2 import cmd_run
|
|
85
|
+
|
|
86
|
+
# Map depth to scale
|
|
87
|
+
scale_map = {1: 30, 2: 70, 3: 150, 4: 200, 5: 300}
|
|
88
|
+
actual_scale = scale or scale_map.get(depth, 150)
|
|
89
|
+
|
|
90
|
+
start = time.time()
|
|
91
|
+
|
|
92
|
+
# Run pipeline
|
|
93
|
+
try:
|
|
94
|
+
mission_id = await asyncio.to_thread(
|
|
95
|
+
cmd_run, topic, think=False, deep=False, force=True, scale=actual_scale
|
|
96
|
+
)
|
|
97
|
+
except Exception as e:
|
|
98
|
+
return ResearchResult(
|
|
99
|
+
topic=topic,
|
|
100
|
+
mission_id="",
|
|
101
|
+
status="error",
|
|
102
|
+
error=str(e),
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
duration = time.time() - start
|
|
106
|
+
|
|
107
|
+
# Load results from DB
|
|
108
|
+
return await self._load_results(topic, mission_id, duration)
|
|
109
|
+
|
|
110
|
+
async def _research_api(
|
|
111
|
+
self, topic: str, depth: int, scale: Optional[int],
|
|
112
|
+
wait: bool, timeout: int
|
|
113
|
+
) -> ResearchResult:
|
|
114
|
+
"""Run research via remote API."""
|
|
115
|
+
import httpx
|
|
116
|
+
|
|
117
|
+
url = f"{self.api_url}/research"
|
|
118
|
+
headers = {}
|
|
119
|
+
if self.api_key:
|
|
120
|
+
headers["Authorization"] = f"Bearer {self.api_key}"
|
|
121
|
+
|
|
122
|
+
async with httpx.AsyncClient(timeout=timeout) as client:
|
|
123
|
+
resp = await client.post(url, json={
|
|
124
|
+
"query": topic,
|
|
125
|
+
"depth": depth,
|
|
126
|
+
"scale": scale,
|
|
127
|
+
}, headers=headers)
|
|
128
|
+
resp.raise_for_status()
|
|
129
|
+
data = resp.json()
|
|
130
|
+
|
|
131
|
+
mission_id = data.get("mission_id", "")
|
|
132
|
+
|
|
133
|
+
if wait and data.get("status") != "done":
|
|
134
|
+
# Poll until done
|
|
135
|
+
start = time.time()
|
|
136
|
+
while time.time() - start < timeout:
|
|
137
|
+
await asyncio.sleep(5)
|
|
138
|
+
status_resp = await client.get(
|
|
139
|
+
f"{self.api_url}/research/{mission_id}/status",
|
|
140
|
+
headers=headers,
|
|
141
|
+
)
|
|
142
|
+
status_data = status_resp.json()
|
|
143
|
+
if status_data.get("status") in ("done", "error"):
|
|
144
|
+
break
|
|
145
|
+
|
|
146
|
+
# Fetch final results
|
|
147
|
+
result_resp = await client.get(
|
|
148
|
+
f"{self.api_url}/research/{mission_id}",
|
|
149
|
+
headers=headers,
|
|
150
|
+
)
|
|
151
|
+
data = result_resp.json()
|
|
152
|
+
|
|
153
|
+
return self._parse_api_result(topic, data)
|
|
154
|
+
|
|
155
|
+
async def _load_results(self, topic: str, mission_id: str, duration: float) -> ResearchResult:
|
|
156
|
+
"""Load results from PostgreSQL."""
|
|
157
|
+
import psycopg2
|
|
158
|
+
|
|
159
|
+
conn = psycopg2.connect(self.db_url)
|
|
160
|
+
cur = conn.cursor()
|
|
161
|
+
|
|
162
|
+
# Load claims
|
|
163
|
+
cur.execute("""
|
|
164
|
+
SELECT claim, confidence, quality_score, source_url, claim_type
|
|
165
|
+
FROM hive_claims
|
|
166
|
+
WHERE mission_id = %s AND (is_garbage = false OR is_garbage IS NULL)
|
|
167
|
+
ORDER BY quality_score DESC
|
|
168
|
+
""", (mission_id,))
|
|
169
|
+
|
|
170
|
+
claims = [
|
|
171
|
+
Claim(
|
|
172
|
+
text=row[0],
|
|
173
|
+
confidence=row[1] or 0.7,
|
|
174
|
+
quality_score=row[2] or 0.0,
|
|
175
|
+
source_url=row[3] or "",
|
|
176
|
+
claim_type=row[4] or "intelligence",
|
|
177
|
+
)
|
|
178
|
+
for row in cur.fetchall()
|
|
179
|
+
]
|
|
180
|
+
|
|
181
|
+
# Load entities
|
|
182
|
+
cur.execute("""
|
|
183
|
+
SELECT name, type, confidence
|
|
184
|
+
FROM hive_entities
|
|
185
|
+
WHERE mission_id = %s
|
|
186
|
+
ORDER BY confidence DESC
|
|
187
|
+
LIMIT 200
|
|
188
|
+
""", (mission_id,))
|
|
189
|
+
|
|
190
|
+
entities = [
|
|
191
|
+
Entity(name=row[0], entity_type=row[1], confidence=row[2] or 0.8)
|
|
192
|
+
for row in cur.fetchall()
|
|
193
|
+
]
|
|
194
|
+
|
|
195
|
+
# Load report (from missions table if exists)
|
|
196
|
+
report = ""
|
|
197
|
+
try:
|
|
198
|
+
cur.execute("""
|
|
199
|
+
SELECT report FROM hive_missions WHERE mission_id = %s
|
|
200
|
+
""", (mission_id,))
|
|
201
|
+
row = cur.fetchone()
|
|
202
|
+
if row and row[0]:
|
|
203
|
+
report = row[0]
|
|
204
|
+
except Exception:
|
|
205
|
+
conn.rollback()
|
|
206
|
+
|
|
207
|
+
conn.close()
|
|
208
|
+
|
|
209
|
+
avg_q = sum(c.quality_score for c in claims) / max(1, len(claims))
|
|
210
|
+
|
|
211
|
+
return ResearchResult(
|
|
212
|
+
topic=topic,
|
|
213
|
+
mission_id=mission_id,
|
|
214
|
+
claims=claims,
|
|
215
|
+
entities=entities,
|
|
216
|
+
report=report,
|
|
217
|
+
sources_processed=0,
|
|
218
|
+
duration_seconds=duration,
|
|
219
|
+
avg_quality=avg_q,
|
|
220
|
+
status="done",
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
def _parse_api_result(self, topic: str, data: dict) -> ResearchResult:
|
|
224
|
+
"""Parse API response into ResearchResult."""
|
|
225
|
+
claims = [
|
|
226
|
+
Claim(
|
|
227
|
+
text=c["text"],
|
|
228
|
+
confidence=c.get("confidence", 0.7),
|
|
229
|
+
quality_score=c.get("quality_score", 0.0),
|
|
230
|
+
source_url=c.get("source_url", ""),
|
|
231
|
+
claim_type=c.get("type", "intelligence"),
|
|
232
|
+
)
|
|
233
|
+
for c in data.get("claims", [])
|
|
234
|
+
]
|
|
235
|
+
|
|
236
|
+
entities = [
|
|
237
|
+
Entity(name=e["name"], entity_type=e.get("type", "unknown"))
|
|
238
|
+
for e in data.get("entities", [])
|
|
239
|
+
]
|
|
240
|
+
|
|
241
|
+
return ResearchResult(
|
|
242
|
+
topic=topic,
|
|
243
|
+
mission_id=data.get("mission_id", ""),
|
|
244
|
+
claims=claims,
|
|
245
|
+
entities=entities,
|
|
246
|
+
report=data.get("report", ""),
|
|
247
|
+
sources_processed=data.get("metrics", {}).get("sources_processed", 0),
|
|
248
|
+
duration_seconds=data.get("metrics", {}).get("duration_seconds", 0),
|
|
249
|
+
avg_quality=data.get("metrics", {}).get("avg_quality", 0),
|
|
250
|
+
status=data.get("status", "done"),
|
|
251
|
+
error=data.get("error"),
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
# ─── Convenience function ────────────────────────────────────────────────────
|
|
256
|
+
|
|
257
|
+
async def research(topic: str, depth: int = 3, **kwargs) -> ResearchResult:
|
|
258
|
+
"""
|
|
259
|
+
Quick research function — auto-detects backend.
|
|
260
|
+
|
|
261
|
+
Usage:
|
|
262
|
+
from behive import research
|
|
263
|
+
result = await research("NVIDIA GPU market 2025")
|
|
264
|
+
for claim in result.excellent_claims:
|
|
265
|
+
print(claim)
|
|
266
|
+
"""
|
|
267
|
+
client = BeHiveClient()
|
|
268
|
+
return await client.research(topic, depth=depth, **kwargs)
|
behive/models.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""Data models for BeHive research results."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
from typing import Optional
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@dataclass
|
|
9
|
+
class Claim:
|
|
10
|
+
"""A structured factual claim extracted from research."""
|
|
11
|
+
text: str
|
|
12
|
+
confidence: float
|
|
13
|
+
quality_score: float
|
|
14
|
+
source_url: str = ""
|
|
15
|
+
claim_type: str = "intelligence"
|
|
16
|
+
extracted_at: Optional[datetime] = None
|
|
17
|
+
enriched: bool = False
|
|
18
|
+
|
|
19
|
+
def __str__(self):
|
|
20
|
+
return f"[{self.quality_score:.2f}] {self.text}"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass
|
|
24
|
+
class Entity:
|
|
25
|
+
"""A named entity discovered during research."""
|
|
26
|
+
name: str
|
|
27
|
+
entity_type: str # person, org, location, technology, product, amount
|
|
28
|
+
confidence: float = 0.8
|
|
29
|
+
mentions: int = 1
|
|
30
|
+
|
|
31
|
+
def __str__(self):
|
|
32
|
+
return f"{self.name} ({self.entity_type})"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@dataclass
|
|
36
|
+
class ResearchResult:
|
|
37
|
+
"""Complete result of a research mission."""
|
|
38
|
+
topic: str
|
|
39
|
+
mission_id: str
|
|
40
|
+
claims: list[Claim] = field(default_factory=list)
|
|
41
|
+
entities: list[Entity] = field(default_factory=list)
|
|
42
|
+
report: str = ""
|
|
43
|
+
|
|
44
|
+
# Metrics
|
|
45
|
+
sources_processed: int = 0
|
|
46
|
+
duration_seconds: float = 0.0
|
|
47
|
+
avg_quality: float = 0.0
|
|
48
|
+
|
|
49
|
+
# Status
|
|
50
|
+
status: str = "pending" # pending, running, done, error
|
|
51
|
+
error: Optional[str] = None
|
|
52
|
+
|
|
53
|
+
@property
|
|
54
|
+
def excellent_claims(self) -> list[Claim]:
|
|
55
|
+
"""Claims with quality >= 0.80."""
|
|
56
|
+
return [c for c in self.claims if c.quality_score >= 0.80]
|
|
57
|
+
|
|
58
|
+
@property
|
|
59
|
+
def summary(self) -> str:
|
|
60
|
+
"""One-line summary."""
|
|
61
|
+
return (
|
|
62
|
+
f"{len(self.claims)} claims (avg {self.avg_quality:.2f}), "
|
|
63
|
+
f"{len(self.entities)} entities, "
|
|
64
|
+
f"{self.sources_processed} sources in {self.duration_seconds:.0f}s"
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
def to_dict(self) -> dict:
|
|
68
|
+
"""Serialize for JSON/API responses."""
|
|
69
|
+
return {
|
|
70
|
+
"topic": self.topic,
|
|
71
|
+
"mission_id": self.mission_id,
|
|
72
|
+
"status": self.status,
|
|
73
|
+
"claims": [
|
|
74
|
+
{"text": c.text, "confidence": c.confidence,
|
|
75
|
+
"quality_score": c.quality_score, "source_url": c.source_url,
|
|
76
|
+
"type": c.claim_type, "enriched": c.enriched}
|
|
77
|
+
for c in self.claims
|
|
78
|
+
],
|
|
79
|
+
"entities": [
|
|
80
|
+
{"name": e.name, "type": e.entity_type,
|
|
81
|
+
"confidence": e.confidence, "mentions": e.mentions}
|
|
82
|
+
for e in self.entities
|
|
83
|
+
],
|
|
84
|
+
"report": self.report,
|
|
85
|
+
"metrics": {
|
|
86
|
+
"sources_processed": self.sources_processed,
|
|
87
|
+
"duration_seconds": self.duration_seconds,
|
|
88
|
+
"avg_quality": self.avg_quality,
|
|
89
|
+
"total_claims": len(self.claims),
|
|
90
|
+
"excellent_claims": len(self.excellent_claims),
|
|
91
|
+
},
|
|
92
|
+
"error": self.error,
|
|
93
|
+
}
|
|
@@ -0,0 +1,632 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: behive
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Research engine that builds structured knowledge graphs from any topic
|
|
5
|
+
Author-email: QA10 <hello@qa10.io>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/qa10devteam/behive
|
|
8
|
+
Project-URL: Documentation, https://behive.dev
|
|
9
|
+
Project-URL: Repository, https://github.com/qa10devteam/behive
|
|
10
|
+
Keywords: research,knowledge-graph,ai,mcp,deep-research
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: aiohttp>=3.9
|
|
22
|
+
Requires-Dist: boto3>=1.28
|
|
23
|
+
Requires-Dist: psycopg2-binary>=2.9
|
|
24
|
+
Requires-Dist: pydantic>=2.0
|
|
25
|
+
Requires-Dist: httpx>=0.25
|
|
26
|
+
Provides-Extra: mcp
|
|
27
|
+
Requires-Dist: fastmcp>=3.0; extra == "mcp"
|
|
28
|
+
Provides-Extra: api
|
|
29
|
+
Requires-Dist: fastapi>=0.100; extra == "api"
|
|
30
|
+
Requires-Dist: uvicorn>=0.20; extra == "api"
|
|
31
|
+
Provides-Extra: qdrant
|
|
32
|
+
Requires-Dist: qdrant-client>=1.7; extra == "qdrant"
|
|
33
|
+
Requires-Dist: sentence-transformers>=2.2; extra == "qdrant"
|
|
34
|
+
Provides-Extra: all
|
|
35
|
+
Requires-Dist: behive[api,mcp,qdrant]; extra == "all"
|
|
36
|
+
Provides-Extra: dev
|
|
37
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
38
|
+
Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
|
|
39
|
+
Dynamic: license-file
|
|
40
|
+
|
|
41
|
+
<p align="center">
|
|
42
|
+
<img src="demo.gif" alt="BeHive — Deep Research Engine" width="720" />
|
|
43
|
+
</p>
|
|
44
|
+
|
|
45
|
+
<h1 align="center">🐝 BeHive</h1>
|
|
46
|
+
|
|
47
|
+
<p align="center">
|
|
48
|
+
<strong>Open-source research engine that extracts structured knowledge from any topic.</strong><br />
|
|
49
|
+
Feed it a question. Get back scored claims, entity graphs, and a synthesized report — not paragraphs of slop.
|
|
50
|
+
</p>
|
|
51
|
+
|
|
52
|
+
<p align="center">
|
|
53
|
+
<a href="https://pypi.org/project/behive"><img src="https://img.shields.io/badge/pip_install-behive-FFB300?style=for-the-badge&logo=python&logoColor=white" /></a>
|
|
54
|
+
<a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-22c55e?style=for-the-badge" /></a>
|
|
55
|
+
<a href="https://api.yu-na.io/docs"><img src="https://img.shields.io/badge/API-Live-4FC3F7?style=for-the-badge&logo=fastapi&logoColor=white" /></a>
|
|
56
|
+
<a href="#mcp-integration"><img src="https://img.shields.io/badge/MCP-Native-AB47BC?style=for-the-badge" /></a>
|
|
57
|
+
</p>
|
|
58
|
+
|
|
59
|
+
<p align="center">
|
|
60
|
+
<a href="#quick-start">Quick Start</a> •
|
|
61
|
+
<a href="#use-with-claude--chatgpt--gemini">Use with AI Assistants</a> •
|
|
62
|
+
<a href="#benchmarks">Benchmarks</a> •
|
|
63
|
+
<a href="#architecture">Architecture</a> •
|
|
64
|
+
<a href="#api-reference">API</a> •
|
|
65
|
+
<a href="#mcp-integration">MCP</a>
|
|
66
|
+
</p>
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## The Problem
|
|
71
|
+
|
|
72
|
+
You ask Claude to research a topic. It gives you a confident-sounding summary based on training data that's months old. No sources. No structure. No way to verify.
|
|
73
|
+
|
|
74
|
+
You ask Perplexity. Better — it cites sources. But the output is still unstructured text. You can't query it, cross-reference it, or build on it.
|
|
75
|
+
|
|
76
|
+
**BeHive is different.** It produces **machine-readable intelligence**: typed claims with confidence scores, entity relationship graphs, and structured JSON you can pipe into any downstream system.
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
Your AI assistant → BeHive → Verified, structured, scored knowledge
|
|
80
|
+
├── 363 claims (avg quality 0.824)
|
|
81
|
+
├── 42 entities with relationships
|
|
82
|
+
└── Synthesized report with citations
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Quick Start
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
pip install behive
|
|
91
|
+
|
|
92
|
+
# Configure your LLM (pick one)
|
|
93
|
+
export BEHIVE_LLM=bedrock # AWS Bedrock Claude (recommended)
|
|
94
|
+
export BEHIVE_LLM=openai # OpenAI GPT-4o
|
|
95
|
+
export BEHIVE_LLM=local # Self-hosted via SGLang/vLLM
|
|
96
|
+
|
|
97
|
+
# Run research from CLI
|
|
98
|
+
behive research "NVIDIA Blackwell GPU production 2026" --scale 30
|
|
99
|
+
|
|
100
|
+
# Or from Python
|
|
101
|
+
python -c "
|
|
102
|
+
from behive import research
|
|
103
|
+
import asyncio
|
|
104
|
+
|
|
105
|
+
result = asyncio.run(research('NVIDIA Blackwell GPU production 2026'))
|
|
106
|
+
print(f'{result.claims_count} claims, avg quality {result.avg_quality:.3f}')
|
|
107
|
+
for claim in result.top_claims(5):
|
|
108
|
+
print(f' [{claim.score:.2f}] {claim.text}')
|
|
109
|
+
"
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## Use with Claude / ChatGPT / Gemini
|
|
115
|
+
|
|
116
|
+
BeHive turns any AI assistant into a **verified research machine**. Three integration paths:
|
|
117
|
+
|
|
118
|
+
### 🟣 Claude (via MCP — zero-code)
|
|
119
|
+
|
|
120
|
+
Add to your Claude Desktop `config.json` or Cursor settings:
|
|
121
|
+
|
|
122
|
+
```json
|
|
123
|
+
{
|
|
124
|
+
"mcpServers": {
|
|
125
|
+
"behive": {
|
|
126
|
+
"url": "http://localhost:8090/mcp",
|
|
127
|
+
"transport": "streamable-http"
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Now Claude can call BeHive natively:
|
|
134
|
+
|
|
135
|
+
> **You:** "Research the EU Carbon Border Adjustment Mechanism — what are the compliance deadlines and industry impacts?"
|
|
136
|
+
>
|
|
137
|
+
> **Claude** *(calls `research_topic`)* **:** "I've launched a deep research mission. BeHive found 312 claims across 156 sources. Here are the key findings, scored by confidence:
|
|
138
|
+
> - [0.94] CBAM transitional phase runs Jan 2024–Dec 2025; full enforcement begins Jan 2026
|
|
139
|
+
> - [0.91] Importers must purchase CBAM certificates matching embedded CO₂ at EU ETS price
|
|
140
|
+
> - [0.88] Steel, cement, aluminium, fertilizers, electricity, and hydrogen are covered sectors
|
|
141
|
+
> ..."
|
|
142
|
+
|
|
143
|
+
Claude's responses shift from "based on my training data" to **"verified against 156 live sources with per-claim confidence scores."**
|
|
144
|
+
|
|
145
|
+
### 🟢 ChatGPT (via Custom GPT / Function Calling)
|
|
146
|
+
|
|
147
|
+
Create a Custom GPT with this action:
|
|
148
|
+
|
|
149
|
+
```yaml
|
|
150
|
+
openapi: 3.0.0
|
|
151
|
+
info:
|
|
152
|
+
title: BeHive Research
|
|
153
|
+
version: 1.0.0
|
|
154
|
+
servers:
|
|
155
|
+
- url: https://your-server.com/api/v1
|
|
156
|
+
paths:
|
|
157
|
+
/research:
|
|
158
|
+
post:
|
|
159
|
+
operationId: startResearch
|
|
160
|
+
requestBody:
|
|
161
|
+
content:
|
|
162
|
+
application/json:
|
|
163
|
+
schema:
|
|
164
|
+
type: object
|
|
165
|
+
properties:
|
|
166
|
+
query:
|
|
167
|
+
type: string
|
|
168
|
+
depth:
|
|
169
|
+
type: integer
|
|
170
|
+
default: 3
|
|
171
|
+
responses:
|
|
172
|
+
'200':
|
|
173
|
+
description: Mission started
|
|
174
|
+
/research/{job_id}/report:
|
|
175
|
+
get:
|
|
176
|
+
operationId: getReport
|
|
177
|
+
parameters:
|
|
178
|
+
- name: job_id
|
|
179
|
+
in: path
|
|
180
|
+
required: true
|
|
181
|
+
schema:
|
|
182
|
+
type: string
|
|
183
|
+
responses:
|
|
184
|
+
'200':
|
|
185
|
+
description: Research report
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Or call from the OpenAI API with function calling:
|
|
189
|
+
|
|
190
|
+
```python
|
|
191
|
+
import openai
|
|
192
|
+
import requests
|
|
193
|
+
|
|
194
|
+
# Start BeHive research
|
|
195
|
+
mission = requests.post("http://localhost:8091/research", json={
|
|
196
|
+
"query": "Quantum computing error correction breakthroughs 2026",
|
|
197
|
+
"depth": 3
|
|
198
|
+
}).json()
|
|
199
|
+
|
|
200
|
+
# Wait for completion, then feed to GPT-4o
|
|
201
|
+
report = requests.get(f"http://localhost:8091/research/{mission['job_id']}/report").json()
|
|
202
|
+
|
|
203
|
+
response = openai.chat.completions.create(
|
|
204
|
+
model="gpt-4o",
|
|
205
|
+
messages=[
|
|
206
|
+
{"role": "system", "content": "You are an analyst. Use the research data below to answer questions. Cite claim IDs."},
|
|
207
|
+
{"role": "user", "content": f"Research data:\n{report['synthesis']}\n\nQuestion: What's the most promising approach to fault-tolerant quantum computing?"}
|
|
208
|
+
]
|
|
209
|
+
)
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### 🔵 Gemini (via API or Vertex AI)
|
|
213
|
+
|
|
214
|
+
```python
|
|
215
|
+
import google.generativeai as genai
|
|
216
|
+
import requests
|
|
217
|
+
|
|
218
|
+
# BeHive produces the research
|
|
219
|
+
claims = requests.get("http://localhost:8091/search", params={
|
|
220
|
+
"query": "autonomous vehicles regulations 2026",
|
|
221
|
+
"limit": 50
|
|
222
|
+
}).json()
|
|
223
|
+
|
|
224
|
+
# Gemini synthesizes with verified data
|
|
225
|
+
model = genai.GenerativeModel("gemini-2.0-flash")
|
|
226
|
+
response = model.generate_content(
|
|
227
|
+
f"Based on these verified research claims (each with a confidence score), "
|
|
228
|
+
f"write a briefing on autonomous vehicle regulation trends:\n\n"
|
|
229
|
+
f"{claims['results']}"
|
|
230
|
+
)
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### Why this matters
|
|
234
|
+
|
|
235
|
+
| Without BeHive | With BeHive |
|
|
236
|
+
|---|---|
|
|
237
|
+
| "Based on my training data..." | "Based on 234 live sources, scored 0.79 avg..." |
|
|
238
|
+
| Hallucination risk | Every claim traced to source URL |
|
|
239
|
+
| Stale knowledge (months old) | Real-time web research |
|
|
240
|
+
| Unstructured text blob | Typed claims, entities, relationships |
|
|
241
|
+
| One-shot, forgotten | Cumulative knowledge graph across sessions |
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
## Drone Arsenal
|
|
246
|
+
|
|
247
|
+
BeHive doesn't just search the web. It deploys **stealth drones** — multi-layered fetch agents that break through anti-bot defenses, paywalls, and rate limits.
|
|
248
|
+
|
|
249
|
+
### 8-Layer Evasion Stack
|
|
250
|
+
|
|
251
|
+
Every URL goes through an **escalation cascade**. If Layer 1 gets blocked, Layer 2 fires. All the way to Layer 8.
|
|
252
|
+
|
|
253
|
+
```
|
|
254
|
+
Layer 1 │ DIRECT — aiohttp + full Chrome 131 headers
|
|
255
|
+
Layer 2 │ UA ROTATION — 10 browser fingerprints (Chrome/Firefox/Safari/Edge)
|
|
256
|
+
Layer 3 │ curl_cffi — TLS impersonation (JA3/JA4 fingerprint matching)
|
|
257
|
+
Layer 4 │ primp — Rust-native TLS, newer fingerprints than curl_cffi
|
|
258
|
+
Layer 5 │ nodriver — Headless Chrome via CDP, passes Cloudflare Bot Management
|
|
259
|
+
Layer 6 │ patchright — Stealth Playwright (no Runtime.enable/Console.enable leak)
|
|
260
|
+
Layer 7 │ Jina relay — r.jina.ai proxy (paywall + captcha bypass)
|
|
261
|
+
Layer 8 │ Archives — Wayback Machine + archive.org fallback
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### What they bypass
|
|
265
|
+
|
|
266
|
+
| Defense | How |
|
|
267
|
+
|---------|-----|
|
|
268
|
+
| Cloudflare | Detected → escalate to nodriver/patchright (JS challenge solved) |
|
|
269
|
+
| DataDome | TLS fingerprint rotation (primp/curl_cffi) |
|
|
270
|
+
| Akamai Bot Manager | CDP-based headless + real browser UA pool |
|
|
271
|
+
| Rate limits | Automatic backoff + UA rotation + parallel diversification |
|
|
272
|
+
| Paywalls | Jina relay proxy + archive.org cache |
|
|
273
|
+
| Turnstile CAPTCHA | patchright stealth Playwright |
|
|
274
|
+
| 403/429 blocks | Smart retry with escalation, never hammer the same layer |
|
|
275
|
+
|
|
276
|
+
### Parallel fetch architecture
|
|
277
|
+
|
|
278
|
+
```
|
|
279
|
+
┌─── HEAD sweep (974+ URLs, async semaphore) ───┐
|
|
280
|
+
│ │
|
|
281
|
+
▼ ▼
|
|
282
|
+
┌─────────────────┐ ┌────────────────┐
|
|
283
|
+
│ Resource Router │ │ Domain Recon │
|
|
284
|
+
│ (8 resource │ │ (tier scoring │
|
|
285
|
+
│ types detected)│ │ reputation) │
|
|
286
|
+
└────────┬────────┘ └───────┬────────┘
|
|
287
|
+
│ │
|
|
288
|
+
┌──────────┼──────────┬──────────┐ │
|
|
289
|
+
▼ ▼ ▼ ▼ ▼
|
|
290
|
+
api_bee pdf_drone std_drone heavy_drone domain_score
|
|
291
|
+
(70 APIs) (VLM parse) (Layer 1-8) (patchright) (0.0 - 1.0)
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
**Routing decisions per resource type:**
|
|
295
|
+
- `api_endpoint` → Direct API bee (structured JSON, no parsing needed)
|
|
296
|
+
- `pdf` → PDF drone (Vision LLM extraction)
|
|
297
|
+
- `static_html` → Standard drone (Layer 1-4 usually sufficient)
|
|
298
|
+
- `spa` → Heavy drone (Layer 5-6, needs JS execution)
|
|
299
|
+
- `paywall` → Jina relay or archive fallback
|
|
300
|
+
- `rss_feed` → RSS bee (structured, fast)
|
|
301
|
+
- `database_portal` → Dedicated connector (custom scraping logic)
|
|
302
|
+
|
|
303
|
+
### 70+ API Sources
|
|
304
|
+
|
|
305
|
+
Scout bees don't just Google. They query **specialized APIs** across 37 categories:
|
|
306
|
+
|
|
307
|
+
| Category | APIs | Examples |
|
|
308
|
+
|----------|------|----------|
|
|
309
|
+
| Academic | 5 | arXiv, Semantic Scholar, CrossRef, OpenAlex, CORE |
|
|
310
|
+
| Financial | 6 | SEC EDGAR, Yahoo Finance, FRED, ECB, World Bank |
|
|
311
|
+
| Government | 5 | TED (EU procurement), SAM.gov, UK FTS, BZP (Poland), GUS |
|
|
312
|
+
| Security | 6 | CVE/NVD, Shodan, VirusTotal, AbuseIPDB |
|
|
313
|
+
| Development | 8 | GitHub, npm, PyPI, crates.io, Docker Hub, Homebrew |
|
|
314
|
+
| ML/AI | 5 | HuggingFace, Papers With Code, Replicate, Ollama |
|
|
315
|
+
| News | 4 | NewsAPI, GNews, TheNewsAPI, Mediastack |
|
|
316
|
+
| Crypto | 2 | CoinGecko, CoinMarketCap |
|
|
317
|
+
| Patents | 1 | Google Patents (via SerpAPI) |
|
|
318
|
+
| Medical | 1 | PubMed/NCBI |
|
|
319
|
+
| ... | 25+ | Trade, geopolitics, environment, demographics, ... |
|
|
320
|
+
|
|
321
|
+
**Total: 70 APIs, 125 endpoints** — each checked per-mission based on topic relevance.
|
|
322
|
+
|
|
323
|
+
---
|
|
324
|
+
|
|
325
|
+
## Benchmarks
|
|
326
|
+
|
|
327
|
+
Real results. No cherry-picking. Scale 30 (standard depth).
|
|
328
|
+
|
|
329
|
+
**Hardware:** EC2 g6.24xlarge — 4× NVIDIA L4 (92 GB VRAM), 96 vCPU, 384 GB RAM
|
|
330
|
+
**Models:** Bedrock Claude Haiku (bulk extraction) + Sonnet (enrichment), SGLang/Qwen on local GPUs
|
|
331
|
+
|
|
332
|
+
| Topic | Claims | Avg Quality | Duration | Sources |
|
|
333
|
+
|:------|-------:|:-----------:|---------:|--------:|
|
|
334
|
+
| NVIDIA GPU market 2026 | 290 | **0.797** | 8 min | 234 |
|
|
335
|
+
| OpenAI GPT-5 capabilities | 574 | **0.789** | 12 min | 174 |
|
|
336
|
+
| EU AI Act enforcement | 267 | **0.759** | 6 min | 130 |
|
|
337
|
+
| Perplexity AI business model | 267 | **0.759** | 7 min | 150 |
|
|
338
|
+
| Meta Llama 4 architecture | 568 | **0.821** | 11 min | 198 |
|
|
339
|
+
|
|
340
|
+
**Quality score meaning:**
|
|
341
|
+
- `0.90+` — Exceptional: specific numbers, dates, sources, fully verifiable
|
|
342
|
+
- `0.82+` — Excellent: multi-dimensional, publication-ready
|
|
343
|
+
- `0.75+` — Good: useful intelligence with some specifics
|
|
344
|
+
- `0.65+` — Acceptable: general facts, entered into DB
|
|
345
|
+
- `<0.55` — Rejected: too vague, not stored
|
|
346
|
+
|
|
347
|
+
> **Honest scoring, no tricks.** No sigmoid rescaling, no artificial inflation. The score is a weighted average of specificity, information density, uniqueness, verifiability, and structure.
|
|
348
|
+
|
|
349
|
+
---
|
|
350
|
+
|
|
351
|
+
## Architecture
|
|
352
|
+
|
|
353
|
+
```
|
|
354
|
+
┌──────────────────────────────────┐
|
|
355
|
+
│ BeHive Pipeline │
|
|
356
|
+
└──────────────────────────────────┘
|
|
357
|
+
│
|
|
358
|
+
┌───────────┬───────────┬───────┴───────┬───────────┬───────────┐
|
|
359
|
+
▼ ▼ ▼ ▼ ▼ ▼
|
|
360
|
+
┌─────────┐ ┌─────────┐ ┌──────────┐ ┌──────────┐ ┌─────────┐ ┌────────┐
|
|
361
|
+
│ SCOUT │ │ HARVEST │ │ PROCESS │ │ V4 │ │ SYNTH │ │ GRAPH │
|
|
362
|
+
│ │ │ │ │ │ │ │ │ │ │ │
|
|
363
|
+
│ Queen │ │ Parallel│ │ BeeHive │ │ Haiku │ │ Claude │ │ Neo4j │
|
|
364
|
+
│ plans │ │ HTTP │ │ fast │ │ extract │ │ report │ │ entity │
|
|
365
|
+
│ 5 axes │ │ 1000+ │ │ extract │ │ + Sonnet │ │ + cite │ │ fuse │
|
|
366
|
+
│ × N │ │ URLs │ │ + score │ │ enrich │ │ │ │ │
|
|
367
|
+
└─────────┘ └─────────┘ └──────────┘ └──────────┘ └─────────┘ └────────┘
|
|
368
|
+
│ │ │ │ │ │
|
|
369
|
+
│ │ ▼ │ │ │
|
|
370
|
+
│ │ ┌──────────────┐ │ │ │
|
|
371
|
+
│ │ │ Quality Gate │ │ │ │
|
|
372
|
+
│ │ │ conf ≥ 0.55 │ │ │ │
|
|
373
|
+
│ │ │ dedup 0.60 │ │ │ │
|
|
374
|
+
│ │ └──────────────┘ │ │ │
|
|
375
|
+
│ │ │ │ │ │
|
|
376
|
+
└──────────────┴────────────┴────────────┴────────────┴──────────┘
|
|
377
|
+
│
|
|
378
|
+
┌─────────┴─────────┐
|
|
379
|
+
│ PostgreSQL │
|
|
380
|
+
│ Claims + KG │
|
|
381
|
+
│ 25K+ records │
|
|
382
|
+
└───────────────────┘
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
**What makes it different from GPT-Researcher:**
|
|
386
|
+
|
|
387
|
+
1. **Dual-model extraction** — Fast model (Haiku) for bulk extraction, powerful model (Sonnet) for enriching thin claims. Not just "summarize this page."
|
|
388
|
+
2. **Quality scoring** — Every claim gets a 0.0-1.0 score. Below threshold = rejected. No filler.
|
|
389
|
+
3. **Knowledge graph** — Entities and relationships persist across missions. Research compounds.
|
|
390
|
+
4. **70+ API sources** — Not just web search. SEC filings, arXiv, patent databases, government APIs.
|
|
391
|
+
5. **Deduplication** — Jaccard 0.60 threshold prevents the same fact from different sources inflating counts.
|
|
392
|
+
|
|
393
|
+
---
|
|
394
|
+
|
|
395
|
+
## API Reference
|
|
396
|
+
|
|
397
|
+
BeHive exposes a REST API (port 8091) and MCP server (port 8090).
|
|
398
|
+
|
|
399
|
+
### Start Research
|
|
400
|
+
|
|
401
|
+
```bash
|
|
402
|
+
curl -X POST http://localhost:8091/research \
|
|
403
|
+
-H "Content-Type: application/json" \
|
|
404
|
+
-d '{
|
|
405
|
+
"query": "SpaceX Starship launch cadence 2026",
|
|
406
|
+
"depth": 3,
|
|
407
|
+
"scale": 30
|
|
408
|
+
}'
|
|
409
|
+
# → {"job_id": "hive_1785227949_815112", "status": "started"}
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
### Stream Progress (SSE)
|
|
413
|
+
|
|
414
|
+
```bash
|
|
415
|
+
curl -N http://localhost:8091/research/hive_1785227949_815112/events
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
```
|
|
419
|
+
event: start
|
|
420
|
+
data: {"topic": "SpaceX Starship...", "status": "scout"}
|
|
421
|
+
|
|
422
|
+
event: phase
|
|
423
|
+
data: {"phase": "process", "event": "started"}
|
|
424
|
+
|
|
425
|
+
event: claims
|
|
426
|
+
data: {"count": 142, "avg_quality": 0.791, "above_082": 23, "new_since_last": 18}
|
|
427
|
+
|
|
428
|
+
event: done
|
|
429
|
+
data: {"total_claims": 363, "avg_quality": 0.824, "sources": 64}
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
### Get Report
|
|
433
|
+
|
|
434
|
+
```bash
|
|
435
|
+
curl http://localhost:8091/research/hive_1785227949_815112/report
|
|
436
|
+
# → {"synthesis": "## SpaceX Starship...", "claims_count": 363, ...}
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
### Search Knowledge
|
|
440
|
+
|
|
441
|
+
```bash
|
|
442
|
+
# Full-text search across all missions
|
|
443
|
+
curl "http://localhost:8091/search?query=NVIDIA+revenue&limit=20"
|
|
444
|
+
|
|
445
|
+
# Entity intelligence
|
|
446
|
+
curl http://localhost:8091/intelligence/entity/NVIDIA
|
|
447
|
+
|
|
448
|
+
# Network graph (2-hop neighborhood)
|
|
449
|
+
curl "http://localhost:8091/intelligence/network/OpenAI?depth=2"
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
### All Endpoints
|
|
453
|
+
|
|
454
|
+
| Method | Path | Description |
|
|
455
|
+
|--------|------|-------------|
|
|
456
|
+
| `POST` | `/research` | Start new mission |
|
|
457
|
+
| `GET` | `/research/{id}/status` | Check progress |
|
|
458
|
+
| `GET` | `/research/{id}/events` | SSE stream |
|
|
459
|
+
| `GET` | `/research/{id}/report` | Get synthesis |
|
|
460
|
+
| `GET` | `/search` | Query claims |
|
|
461
|
+
| `GET` | `/intelligence/entity/{name}` | Entity details |
|
|
462
|
+
| `GET` | `/intelligence/network/{name}` | Relationship graph |
|
|
463
|
+
| `GET` | `/intelligence/stats` | System statistics |
|
|
464
|
+
|
|
465
|
+
Full Swagger docs: `http://localhost:8091/docs`
|
|
466
|
+
|
|
467
|
+
---
|
|
468
|
+
|
|
469
|
+
## MCP Integration
|
|
470
|
+
|
|
471
|
+
BeHive implements the [Model Context Protocol](https://modelcontextprotocol.io) — the emerging standard for AI tool connectivity.
|
|
472
|
+
|
|
473
|
+
```json
|
|
474
|
+
{
|
|
475
|
+
"mcpServers": {
|
|
476
|
+
"behive": {
|
|
477
|
+
"url": "http://localhost:8090/mcp",
|
|
478
|
+
"transport": "streamable-http"
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
**Compatible with:**
|
|
485
|
+
- Claude Desktop / Claude Code
|
|
486
|
+
- Cursor IDE
|
|
487
|
+
- Windsurf
|
|
488
|
+
- n8n (via MCP node)
|
|
489
|
+
- Any MCP-compatible client
|
|
490
|
+
|
|
491
|
+
**Tools exposed:**
|
|
492
|
+
|
|
493
|
+
| Tool | Description |
|
|
494
|
+
|------|-------------|
|
|
495
|
+
| `research_topic` | Start deep research on any topic |
|
|
496
|
+
| `mission_status` | Poll progress (phase, quality, claims) |
|
|
497
|
+
| `get_report` | Get the synthesized markdown report |
|
|
498
|
+
| `search_knowledge` | Query claims across all missions |
|
|
499
|
+
| `list_missions` | See completed research history |
|
|
500
|
+
|
|
501
|
+
---
|
|
502
|
+
|
|
503
|
+
## Self-Hosting
|
|
504
|
+
|
|
505
|
+
### Requirements
|
|
506
|
+
|
|
507
|
+
- Python 3.10+
|
|
508
|
+
- PostgreSQL 14+ (claims storage)
|
|
509
|
+
- LLM access (Bedrock, OpenAI, or local SGLang/vLLM)
|
|
510
|
+
- Optional: Neo4j (knowledge graph), Qdrant (embeddings)
|
|
511
|
+
|
|
512
|
+
### Docker (coming soon)
|
|
513
|
+
|
|
514
|
+
```bash
|
|
515
|
+
docker compose up -d
|
|
516
|
+
behive research "your topic" --scale 30
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
### Manual Setup
|
|
520
|
+
|
|
521
|
+
```bash
|
|
522
|
+
git clone https://github.com/qa10devteam/behive.git
|
|
523
|
+
cd behive
|
|
524
|
+
pip install -e .
|
|
525
|
+
|
|
526
|
+
# PostgreSQL
|
|
527
|
+
createdb hive
|
|
528
|
+
behive db init
|
|
529
|
+
|
|
530
|
+
# Configure
|
|
531
|
+
export BEHIVE_DB_URL="postgresql://user:pass@localhost:5432/hive"
|
|
532
|
+
export BEHIVE_LLM=bedrock # or openai, local
|
|
533
|
+
|
|
534
|
+
# Start services
|
|
535
|
+
behive api start # REST API on :8091
|
|
536
|
+
behive mcp start # MCP server on :8090
|
|
537
|
+
```
|
|
538
|
+
|
|
539
|
+
---
|
|
540
|
+
|
|
541
|
+
## How It Works (for humans)
|
|
542
|
+
|
|
543
|
+
1. **You give it a topic.** "NVIDIA GPU market 2026"
|
|
544
|
+
|
|
545
|
+
2. **Scout bees plan the research.** The Queen decomposes it into 5 axes (market share, financials, products, competition, supply chain). Generates 12-14 search queries per axis. Checks 70+ APIs.
|
|
546
|
+
|
|
547
|
+
3. **Harvest bees collect sources.** Parallel HTTP fetches ~1000 URLs. HEAD sweep first (fast), then full content extraction on promising ones. Typically lands 60-90 usable documents.
|
|
548
|
+
|
|
549
|
+
4. **Worker bees extract claims.** This is where BeHive shines:
|
|
550
|
+
- Every document gets parsed into atomic, verifiable claims
|
|
551
|
+
- Each claim scored on 5 dimensions (specificity, density, uniqueness, verifiability, structure)
|
|
552
|
+
- Claims below 0.55 quality → rejected
|
|
553
|
+
- Thin claims (missing dates/numbers) → enriched by Sonnet
|
|
554
|
+
- Duplicate claims (Jaccard >0.60) → merged
|
|
555
|
+
|
|
556
|
+
5. **The Queen synthesizes.** Claude weaves the verified claims into a structured report with inline citations. No hallucination — every statement maps to a scored claim.
|
|
557
|
+
|
|
558
|
+
6. **Knowledge graph grows.** Entities (companies, people, products, amounts) and their relationships are stored in Neo4j. Next research mission on a related topic starts with existing context.
|
|
559
|
+
|
|
560
|
+
---
|
|
561
|
+
|
|
562
|
+
## Configuration
|
|
563
|
+
|
|
564
|
+
| Variable | Default | Description |
|
|
565
|
+
|----------|---------|-------------|
|
|
566
|
+
| `BEHIVE_DB_URL` | `postgresql://localhost/hive` | PostgreSQL connection |
|
|
567
|
+
| `BEHIVE_LLM` | `bedrock` | LLM provider: `bedrock`, `openai`, `local` |
|
|
568
|
+
| `BEHIVE_LLM_URL` | — | Local LLM endpoint (for `local` mode) |
|
|
569
|
+
| `BEHIVE_NEO4J_URI` | `bolt://localhost:7687` | Neo4j (optional) |
|
|
570
|
+
| `BEHIVE_QDRANT_URL` | `http://localhost:6333` | Qdrant (optional) |
|
|
571
|
+
| `BEHIVE_SCALE` | `30` | Default research scale (30-300) |
|
|
572
|
+
| `BEHIVE_QUALITY_GATE` | `0.55` | Minimum claim quality to store |
|
|
573
|
+
| `AWS_PROFILE` | `default` | For Bedrock authentication |
|
|
574
|
+
| `OPENAI_API_KEY` | — | For OpenAI mode |
|
|
575
|
+
|
|
576
|
+
---
|
|
577
|
+
|
|
578
|
+
## Comparison
|
|
579
|
+
|
|
580
|
+
| | BeHive | GPT-Researcher | Tavily | Perplexity | STORM |
|
|
581
|
+
|---|:---:|:---:|:---:|:---:|:---:|
|
|
582
|
+
| Output format | Structured JSON | Markdown text | JSON snippets | Text | Wiki article |
|
|
583
|
+
| Per-claim scoring | ✅ 0.0-1.0 | ❌ | ❌ | ❌ | ❌ |
|
|
584
|
+
| Knowledge graph | ✅ Neo4j | ❌ | ❌ | ❌ | ❌ |
|
|
585
|
+
| Cross-session memory | ✅ Cumulative | ❌ | ❌ | ❌ | ❌ |
|
|
586
|
+
| MCP native | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
587
|
+
| API sources (70+) | ✅ | ❌ Web only | ⚠️ Search | ⚠️ Search | ❌ Web only |
|
|
588
|
+
| Self-hosted | ✅ Full | ⚠️ Needs API keys | ❌ Cloud | ❌ Cloud | ✅ |
|
|
589
|
+
| Quality deduplication | ✅ Jaccard 0.60 | ❌ | ❌ | ❌ | ❌ |
|
|
590
|
+
| SSE streaming | ✅ Real-time | ❌ | ❌ | ❌ | ❌ |
|
|
591
|
+
| Pricing | **Free (MIT)** | Free (MIT) | $0.01/search | $20/mo+ | Free (MIT) |
|
|
592
|
+
|
|
593
|
+
---
|
|
594
|
+
|
|
595
|
+
## Roadmap
|
|
596
|
+
|
|
597
|
+
- [x] V4 pipeline (Haiku + Sonnet extraction)
|
|
598
|
+
- [x] Quality scoring (avg 0.82+ achieved)
|
|
599
|
+
- [x] REST API (27 endpoints)
|
|
600
|
+
- [x] MCP Server (Streamable HTTP)
|
|
601
|
+
- [x] SSE streaming (real-time progress)
|
|
602
|
+
- [x] Knowledge graph (Neo4j)
|
|
603
|
+
- [x] 70+ API sources
|
|
604
|
+
- [ ] `pip install behive` (PyPI)
|
|
605
|
+
- [ ] Docker Compose one-liner
|
|
606
|
+
- [ ] n8n community node
|
|
607
|
+
- [ ] Web UI dashboard
|
|
608
|
+
- [ ] Multi-tenant API keys
|
|
609
|
+
- [ ] Webhook callbacks
|
|
610
|
+
|
|
611
|
+
---
|
|
612
|
+
|
|
613
|
+
## Contributing
|
|
614
|
+
|
|
615
|
+
```bash
|
|
616
|
+
git clone https://github.com/qa10devteam/behive.git
|
|
617
|
+
cd behive
|
|
618
|
+
pip install -e ".[dev]"
|
|
619
|
+
pytest
|
|
620
|
+
```
|
|
621
|
+
|
|
622
|
+
---
|
|
623
|
+
|
|
624
|
+
## License
|
|
625
|
+
|
|
626
|
+
MIT — use it, fork it, ship it, sell it.
|
|
627
|
+
|
|
628
|
+
---
|
|
629
|
+
|
|
630
|
+
<p align="center">
|
|
631
|
+
<sub>Built by <a href="https://qa10.io">QA10</a> · Structured knowledge, not text soup.</sub>
|
|
632
|
+
</p>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
behive/__init__.py,sha256=XIyznSSv7xVmVclv9VKO01QZ-IdRrLPfFXrFlh-zPSw,591
|
|
2
|
+
behive/cli.py,sha256=keTtWuqbfFxZkyaFa8giONq4Meu32tJ-5OCS4U0S-pg,2287
|
|
3
|
+
behive/client.py,sha256=FUexS0n97_T30TaEcYGsxAB0uq6Nq4eXnW6Dd8-Vcyg,9026
|
|
4
|
+
behive/models.py,sha256=0cc6q_8DDzsVY4WLHKAtFmVPZcUjFOQGw0zgA9RGZBc,2869
|
|
5
|
+
behive-0.1.0.dist-info/licenses/LICENSE,sha256=4gsrrH9X3jwN1SuWq0EAviwZUaweFzMPc0v-wl0jiIE,1068
|
|
6
|
+
behive-0.1.0.dist-info/METADATA,sha256=a4OlgrWs6jde5WX7mo3wTzE6HpX62eZcnEOE3N0Cn-o,23890
|
|
7
|
+
behive-0.1.0.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
8
|
+
behive-0.1.0.dist-info/entry_points.txt,sha256=kjo8szcE7UeCajy6bC4yboKbRVEIxuWOZXhhnEYmP6I,43
|
|
9
|
+
behive-0.1.0.dist-info/top_level.txt,sha256=lVMB0qdBd-RT_qKN5A1qBJS1uW493lDXJ-tDMuvGecA,7
|
|
10
|
+
behive-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 qa10devteam
|
|
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 @@
|
|
|
1
|
+
behive
|