Skip to content

armgit / LEANN

Public Imported from GitHub
0

[MLsys2026 Best Paper]: https://arxiv.org/abs/2506.08276. RAG on Everything with LEANN. Enjoy 97% storage savings while running a fast, accurate, and 100% private RAG application on your personal device.

fix(server, interactive): resolve pydantic ForwardRef and readline history errors (#304)

Rob Grayf86beeb23aea
diff --git a/packages/leann-core/src/leann/interactive_utils.py b/packages/leann-core/src/leann/interactive_utils.py
index da05d8b..884e7b7 100644
--- a/packages/leann-core/src/leann/interactive_utils.py
+++ b/packages/leann-core/src/leann/interactive_utils.py
@@ -73,7 +73,7 @@ class InteractiveSession:
try:
rl.read_history_file(str(history_file))
rl.set_history_length(1000)
- except FileNotFoundError:
+ except (FileNotFoundError, FileExistsError, OSError):
pass
# Save history on exit
diff --git a/packages/leann-core/src/leann/server.py b/packages/leann-core/src/leann/server.py
index ecc07a3..2041513 100644
--- a/packages/leann-core/src/leann/server.py
+++ b/packages/leann-core/src/leann/server.py
@@ -19,10 +19,30 @@ import os
from pathlib import Path
from typing import Any
+from pydantic import BaseModel as _BaseModel
+
from .api import LeannSearcher
from .cli import LeannCLI
+class SearchRequest(_BaseModel):
+ query: str
+ top_k: int = 5
+ complexity: int = 64
+ beam_width: int = 1
+ prune_ratio: float = 0.0
+ recompute_embeddings: bool = True
+ pruning_strategy: str = "global"
+ use_grep: bool = False
+
+
+class SearchResultModel(_BaseModel):
+ id: str
+ score: float
+ text: str
+ metadata: dict[str, Any]
+
+
def _ensure_fastapi():
"""Lazy import FastAPI and Pydantic, with a clear error if missing."""
try:
@@ -95,22 +115,6 @@ def create_app():
FastAPI, HTTPException, BaseModel = _ensure_fastapi()
- class SearchRequest(BaseModel):
- query: str
- top_k: int = 5
- complexity: int = 64
- beam_width: int = 1
- prune_ratio: float = 0.0
- recompute_embeddings: bool = True
- pruning_strategy: str = "global"
- use_grep: bool = False
-
- class SearchResultModel(BaseModel):
- id: str
- score: float
- text: str
- metadata: dict[str, Any]
-
app = FastAPI(
title="LEANN Vector DB Server",
description=(