beaver-db 0.17.6__py3-none-any.whl → 0.18.1__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.
Potentially problematic release.
This version of beaver-db might be problematic. Click here for more details.
- beaver/__init__.py +2 -0
- beaver/cli.py +25 -0
- beaver/collections.py +11 -4
- beaver/server.py +9 -9
- {beaver_db-0.17.6.dist-info → beaver_db-0.18.1.dist-info}/METADATA +15 -3
- {beaver_db-0.17.6.dist-info → beaver_db-0.18.1.dist-info}/RECORD +9 -9
- {beaver_db-0.17.6.dist-info → beaver_db-0.18.1.dist-info}/WHEEL +0 -0
- {beaver_db-0.17.6.dist-info → beaver_db-0.18.1.dist-info}/entry_points.txt +0 -0
- {beaver_db-0.17.6.dist-info → beaver_db-0.18.1.dist-info}/licenses/LICENSE +0 -0
beaver/__init__.py
CHANGED
beaver/cli.py
CHANGED
|
@@ -1,10 +1,35 @@
|
|
|
1
1
|
import typer
|
|
2
2
|
import rich
|
|
3
3
|
from typing_extensions import Annotated
|
|
4
|
+
import beaver
|
|
4
5
|
|
|
5
6
|
app = typer.Typer()
|
|
6
7
|
|
|
7
8
|
|
|
9
|
+
def version_callback(value: bool):
|
|
10
|
+
if value:
|
|
11
|
+
print(beaver.__version__)
|
|
12
|
+
raise typer.Exit()
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@app.callback()
|
|
16
|
+
def main(
|
|
17
|
+
version: Annotated[
|
|
18
|
+
bool,
|
|
19
|
+
typer.Option(
|
|
20
|
+
"--version",
|
|
21
|
+
callback=version_callback,
|
|
22
|
+
is_eager=True,
|
|
23
|
+
help="Show the version and exit.",
|
|
24
|
+
),
|
|
25
|
+
] = False,
|
|
26
|
+
):
|
|
27
|
+
"""
|
|
28
|
+
BeaverDB command-line interface.
|
|
29
|
+
"""
|
|
30
|
+
pass
|
|
31
|
+
|
|
32
|
+
|
|
8
33
|
@app.command()
|
|
9
34
|
def serve(
|
|
10
35
|
database: Annotated[
|
beaver/collections.py
CHANGED
|
@@ -96,13 +96,20 @@ class Document(Model):
|
|
|
96
96
|
def to_dict(self) -> dict[str, Any]:
|
|
97
97
|
"""Serializes the document's metadata to a dictionary."""
|
|
98
98
|
metadata = self.__dict__.copy()
|
|
99
|
-
metadata
|
|
100
|
-
metadata.pop("id", None)
|
|
99
|
+
metadata["embedding"] = self.embedding.tolist() if self.embedding is not None else None
|
|
101
100
|
return metadata
|
|
102
101
|
|
|
103
102
|
def __repr__(self):
|
|
103
|
+
d = self.to_dict()
|
|
104
|
+
d.pop("embedding")
|
|
104
105
|
metadata_str = ", ".join(f"{k}={v!r}" for k, v in self.to_dict().items())
|
|
105
|
-
return f"Document(
|
|
106
|
+
return f"Document({metadata_str})"
|
|
107
|
+
|
|
108
|
+
def model_dump_json(self) -> str:
|
|
109
|
+
d = self.to_dict()
|
|
110
|
+
d.pop("embedding")
|
|
111
|
+
d.pop("id")
|
|
112
|
+
return json.dumps(d)
|
|
106
113
|
|
|
107
114
|
|
|
108
115
|
class CollectionManager[D: Document]:
|
|
@@ -323,7 +330,7 @@ class CollectionManager[D: Document]:
|
|
|
323
330
|
if doc_id in doc_map:
|
|
324
331
|
doc = doc_map[doc_id]
|
|
325
332
|
distance = distance_map[doc_id]
|
|
326
|
-
final_results.append((doc, distance))
|
|
333
|
+
final_results.append((doc, float(distance)))
|
|
327
334
|
|
|
328
335
|
return final_results
|
|
329
336
|
|
beaver/server.py
CHANGED
|
@@ -270,7 +270,7 @@ def build(db: BeaverDB) -> FastAPI:
|
|
|
270
270
|
def get_all_documents(name: str) -> List[dict]:
|
|
271
271
|
"""Retrieves all documents in the collection."""
|
|
272
272
|
collection = db.collection(name)
|
|
273
|
-
return [doc.
|
|
273
|
+
return [doc.to_dict() for doc in collection]
|
|
274
274
|
|
|
275
275
|
@app.post("/collections/{name}/index", tags=["Collections"])
|
|
276
276
|
def index_document(name: str, req: IndexRequest):
|
|
@@ -281,8 +281,8 @@ def build(db: BeaverDB) -> FastAPI:
|
|
|
281
281
|
collection.index(doc, fts=req.fts, fuzzy=req.fuzzy)
|
|
282
282
|
return {"status": "ok", "id": doc.id}
|
|
283
283
|
except TypeError as e:
|
|
284
|
-
if "
|
|
285
|
-
raise HTTPException(status_code=501, detail="Vector indexing requires the '[
|
|
284
|
+
if "vector" in str(e):
|
|
285
|
+
raise HTTPException(status_code=501, detail="Vector indexing requires the '[vector]' extra. Install with: pip install \"beaver-db[vector]\"")
|
|
286
286
|
raise e
|
|
287
287
|
|
|
288
288
|
@app.post("/collections/{name}/search", tags=["Collections"])
|
|
@@ -291,10 +291,10 @@ def build(db: BeaverDB) -> FastAPI:
|
|
|
291
291
|
collection = db.collection(name)
|
|
292
292
|
try:
|
|
293
293
|
results = collection.search(vector=req.vector, top_k=req.top_k)
|
|
294
|
-
return [{"document": doc.
|
|
294
|
+
return [{"document": doc.to_dict(), "distance": dist} for doc, dist in results]
|
|
295
295
|
except TypeError as e:
|
|
296
|
-
if "
|
|
297
|
-
raise HTTPException(status_code=501, detail="Vector search requires the '[
|
|
296
|
+
if "vector" in str(e):
|
|
297
|
+
raise HTTPException(status_code=501, detail="Vector search requires the '[vector]' extra. Install with: pip install \"beaver-db[vector]\"")
|
|
298
298
|
raise e
|
|
299
299
|
|
|
300
300
|
@app.post("/collections/{name}/match", tags=["Collections"])
|
|
@@ -302,7 +302,7 @@ def build(db: BeaverDB) -> FastAPI:
|
|
|
302
302
|
"""Performs a full-text or fuzzy search on the collection."""
|
|
303
303
|
collection = db.collection(name)
|
|
304
304
|
results = collection.match(query=req.query, on=req.on, top_k=req.top_k, fuzziness=req.fuzziness)
|
|
305
|
-
return [{"document": doc.
|
|
305
|
+
return [{"document": doc.to_dict(), "score": score} for doc, score in results]
|
|
306
306
|
|
|
307
307
|
@app.post("/collections/{name}/connect", tags=["Collections"])
|
|
308
308
|
def connect_documents(name: str, req: ConnectRequest):
|
|
@@ -319,7 +319,7 @@ def build(db: BeaverDB) -> FastAPI:
|
|
|
319
319
|
collection = db.collection(name)
|
|
320
320
|
doc = Document(id=doc_id)
|
|
321
321
|
neighbors = collection.neighbors(doc, label=label)
|
|
322
|
-
return [n.
|
|
322
|
+
return [n.to_dict() for n in neighbors]
|
|
323
323
|
|
|
324
324
|
@app.post("/collections/{name}/{doc_id}/walk", tags=["Collections"])
|
|
325
325
|
def walk_graph(name: str, doc_id: str, req: WalkRequest) -> List[dict]:
|
|
@@ -327,7 +327,7 @@ def build(db: BeaverDB) -> FastAPI:
|
|
|
327
327
|
collection = db.collection(name)
|
|
328
328
|
source_doc = Document(id=doc_id)
|
|
329
329
|
results = collection.walk(source=source_doc, labels=req.labels, depth=req.depth, direction=req.direction)
|
|
330
|
-
return [doc.
|
|
330
|
+
return [doc.to_dict() for doc in results]
|
|
331
331
|
|
|
332
332
|
return app
|
|
333
333
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: beaver-db
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.18.1
|
|
4
4
|
Summary: Fast, embedded, and multi-modal DB based on SQLite for AI-powered applications.
|
|
5
5
|
License-File: LICENSE
|
|
6
6
|
Classifier: License :: OSI Approved :: MIT License
|
|
@@ -93,7 +93,7 @@ To include optional features, you can install them as extras:
|
|
|
93
93
|
|
|
94
94
|
```bash
|
|
95
95
|
# For vector search capabilities
|
|
96
|
-
pip install "beaver-db[
|
|
96
|
+
pip install "beaver-db[vector]"
|
|
97
97
|
|
|
98
98
|
# For the REST API server and CLI
|
|
99
99
|
pip install "beaver-db[server,cli]"
|
|
@@ -102,6 +102,16 @@ pip install "beaver-db[server,cli]"
|
|
|
102
102
|
pip install "beaver-db[full]"
|
|
103
103
|
```
|
|
104
104
|
|
|
105
|
+
### Running with Docker
|
|
106
|
+
For a fully embedded and lightweight solution, you can run the BeaverDB REST API server using Docker. This is the easiest way to get a self-hosted instance up and running.
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
docker run -p 8000:8000 -v $(pwd)/data:/app apiad/beaverdb
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
This command will start the BeaverDB server, and your database file will be stored in the data directory on your host machine. You can access the API at <http://localhost:8000>.
|
|
113
|
+
|
|
114
|
+
|
|
105
115
|
## Quickstart
|
|
106
116
|
|
|
107
117
|
Get up and running in 30 seconds. This example showcases a dictionary, a list, and full-text search in a single script.
|
|
@@ -401,6 +411,8 @@ For more in-depth examples, check out the scripts in the `examples/` directory:
|
|
|
401
411
|
These are some of the features and improvements planned for future releases:
|
|
402
412
|
|
|
403
413
|
- **Async API**: Extend the async support with on-demand wrappers for all features besides channels.
|
|
414
|
+
- **Type-Safe Models**: Enhance built-in `Model` to handle recursive and embedded types.
|
|
415
|
+
- **Drop-in REST Client**: Implement a `BeaverClient` class that acts as a drop-in replacement for `BeaverDB` but instead of a local database file, it works against a REST API server.
|
|
404
416
|
|
|
405
417
|
Check out the [roadmap](roadmap.md) for a detailed list of upcoming features and design ideas.
|
|
406
418
|
|
|
@@ -408,4 +420,4 @@ If you think of something that would make `beaver` more useful for your use case
|
|
|
408
420
|
|
|
409
421
|
## License
|
|
410
422
|
|
|
411
|
-
This project is licensed under the MIT License.
|
|
423
|
+
This project is licensed under the MIT License.
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
beaver/__init__.py,sha256=
|
|
1
|
+
beaver/__init__.py,sha256=QkP3H8ah0QpWqaryT3yjNFX07zjGHMoWgu4dWDHH9eQ,125
|
|
2
2
|
beaver/blobs.py,sha256=YkIEskHD6oHRaJTF0P25HrTT8LqM-REyV_UBPVQxeqQ,4055
|
|
3
3
|
beaver/channels.py,sha256=kIuwKMDBdDQObaKT23znsMXzfpKfE7pXSxvf-u4LlpY,9554
|
|
4
|
-
beaver/cli.py,sha256=
|
|
5
|
-
beaver/collections.py,sha256=
|
|
4
|
+
beaver/cli.py,sha256=Sxm-mYU3LGd4tIqw-5LHb0ektWebjV9vn51hm-CMJD0,2232
|
|
5
|
+
beaver/collections.py,sha256=CBJSBmJ0LuVI068iRJ2HCXdivxjw51FJOu2BC_54Lfw,24825
|
|
6
6
|
beaver/core.py,sha256=68vjuEbkJTHv4SltCLCrgs34BpLCeL602oJZ6CJ34Zo,14560
|
|
7
7
|
beaver/dicts.py,sha256=Xp8lPfQt08O8zCbptQLWQLO79OxG6uAVER6ryj3SScQ,5495
|
|
8
8
|
beaver/lists.py,sha256=rfJ8uTNLkMREYc0uGx0z1VKt2m3eR9hvbdvDD58EbmQ,10140
|
|
9
9
|
beaver/logs.py,sha256=a5xenwl5NZeegIU0dWVEs67lvaHzzw-JRAZtEzNNO3E,9529
|
|
10
10
|
beaver/queues.py,sha256=Fr3oie63EtceSoiC8EOEDSLu1tDI8q2MYLXd8MEeC3g,6476
|
|
11
|
-
beaver/server.py,sha256=
|
|
11
|
+
beaver/server.py,sha256=ZYbzcar_xQP3vCgvmrRobIx0L8dfcHtvxRAQNcniJwo,13547
|
|
12
12
|
beaver/types.py,sha256=WZLINf7hy6zdKdAFQK0EVMSl5vnY_KnrHXNdXgAKuPg,1582
|
|
13
13
|
beaver/vectors.py,sha256=qvI6RwUOGrhVH5d6PUmI3jKDaoDotMy0iy-bHyvmXks,18496
|
|
14
|
-
beaver_db-0.
|
|
15
|
-
beaver_db-0.
|
|
16
|
-
beaver_db-0.
|
|
17
|
-
beaver_db-0.
|
|
18
|
-
beaver_db-0.
|
|
14
|
+
beaver_db-0.18.1.dist-info/METADATA,sha256=CbtpFh4hUSpVJEegCeRTpATfZeG81Pgybt1ScCyeEz8,21232
|
|
15
|
+
beaver_db-0.18.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
16
|
+
beaver_db-0.18.1.dist-info/entry_points.txt,sha256=bd5E2s45PoBdtdR9-ToKSdLNhmHp8naV1lWP5mOzlrc,42
|
|
17
|
+
beaver_db-0.18.1.dist-info/licenses/LICENSE,sha256=1xrIY5JnMk_QDQzsqmVzPIIyCgZAkWCC8kF2Ddo1UT0,1071
|
|
18
|
+
beaver_db-0.18.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|