haiku.rag 0.7.2__py3-none-any.whl → 0.7.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of haiku.rag might be problematic. Click here for more details.

haiku/rag/app.py CHANGED
@@ -50,8 +50,13 @@ class HaikuRAGApp:
50
50
 
51
51
  async def delete_document(self, doc_id: str):
52
52
  async with HaikuRAG(db_path=self.db_path) as self.client:
53
- await self.client.delete_document(doc_id)
54
- self.console.print(f"[b]Document {doc_id} deleted successfully.[/b]")
53
+ deleted = await self.client.delete_document(doc_id)
54
+ if deleted:
55
+ self.console.print(f"[b]Document {doc_id} deleted successfully.[/b]")
56
+ else:
57
+ self.console.print(
58
+ f"[yellow]Document with id {doc_id} not found.[/yellow]"
59
+ )
55
60
 
56
61
  async def search(self, query: str, limit: int = 5):
57
62
  async with HaikuRAG(db_path=self.db_path) as self.client:
haiku/rag/cli.py CHANGED
@@ -8,6 +8,7 @@ from rich.console import Console
8
8
 
9
9
  from haiku.rag.app import HaikuRAGApp
10
10
  from haiku.rag.config import Config
11
+ from haiku.rag.logging import configure_cli_logging
11
12
  from haiku.rag.migration import migrate_sqlite_to_lancedb
12
13
  from haiku.rag.utils import is_up_to_date
13
14
 
@@ -21,6 +22,65 @@ cli = typer.Typer(
21
22
  console = Console()
22
23
 
23
24
 
25
+ def complete_document_ids(ctx: typer.Context, incomplete: str):
26
+ """Autocomplete document IDs from the selected DB."""
27
+ db_path = ctx.params.get("db") or (Config.DEFAULT_DATA_DIR / "haiku.rag.lancedb")
28
+
29
+ try:
30
+ from haiku.rag.client import HaikuRAG
31
+
32
+ async def _list_ids():
33
+ async with HaikuRAG(db_path) as client:
34
+ docs = await client.list_documents()
35
+ return [d.id for d in docs if d.id]
36
+
37
+ ids = asyncio.run(_list_ids())
38
+ except Exception:
39
+ return []
40
+
41
+ return [i for i in ids if i and i.startswith(incomplete)]
42
+
43
+
44
+ def complete_local_paths(ctx: typer.Context, incomplete: str) -> list[str]:
45
+ """Autocomplete local filesystem paths.
46
+
47
+ Provides directory/file suggestions based on the current incomplete input.
48
+ Does not validate or restrict to specific extensions to keep it flexible
49
+ (URLs are still allowed to be typed manually).
50
+ """
51
+ try:
52
+ text = incomplete or ""
53
+
54
+ # Expand user home
55
+ from os.path import expanduser
56
+
57
+ expanded = expanduser(text)
58
+ p = Path(expanded)
59
+
60
+ # Choose directory to list and prefix to filter
61
+ if text == "" or text.endswith(("/", "\\")):
62
+ directory = p
63
+ prefix = ""
64
+ else:
65
+ directory = p.parent
66
+ prefix = p.name
67
+
68
+ if not directory.exists():
69
+ return []
70
+
71
+ suggestions: list[str] = []
72
+ for entry in directory.iterdir():
73
+ name = entry.name
74
+ if not prefix or name.startswith(prefix):
75
+ suggestion = str(directory / name)
76
+ if entry.is_dir():
77
+ suggestion += "/"
78
+ suggestions.append(suggestion)
79
+ return suggestions
80
+ except Exception:
81
+ return []
82
+
83
+
24
84
  async def check_version():
25
85
  """Check if haiku.rag is up to date and show warning if not."""
26
86
  up_to_date, current_version, latest_version = await is_up_to_date()
@@ -49,6 +109,8 @@ def main(
49
109
  ),
50
110
  ):
51
111
  """haiku.rag CLI - Vector database RAG system"""
112
+ # Ensure only haiku.rag logs are emitted in CLI context
113
+ configure_cli_logging()
52
114
  # Run version check before any command
53
115
  asyncio.run(check_version())
54
116
 
@@ -84,6 +146,7 @@ def add_document_text(
84
146
  def add_document_src(
85
147
  source: str = typer.Argument(
86
148
  help="The file path or URL of the document to add",
149
+ autocompletion=complete_local_paths,
87
150
  ),
88
151
  db: Path = typer.Option(
89
152
  Config.DEFAULT_DATA_DIR / "haiku.rag.lancedb",
@@ -99,6 +162,7 @@ def add_document_src(
99
162
  def get_document(
100
163
  doc_id: str = typer.Argument(
101
164
  help="The ID of the document to get",
165
+ autocompletion=complete_document_ids,
102
166
  ),
103
167
  db: Path = typer.Option(
104
168
  Config.DEFAULT_DATA_DIR / "haiku.rag.lancedb",
@@ -114,6 +178,7 @@ def get_document(
114
178
  def delete_document(
115
179
  doc_id: str = typer.Argument(
116
180
  help="The ID of the document to delete",
181
+ autocompletion=complete_document_ids,
117
182
  ),
118
183
  db: Path = typer.Option(
119
184
  Config.DEFAULT_DATA_DIR / "haiku.rag.lancedb",
@@ -125,6 +190,10 @@ def delete_document(
125
190
  asyncio.run(app.delete_document(doc_id=doc_id))
126
191
 
127
192
 
193
+ # Add alias `rm` for delete
194
+ cli.command("rm", help="Alias for delete: remove a document by its ID")(delete_document)
195
+
196
+
128
197
  @cli.command("search", help="Search for documents by a query")
129
198
  def search(
130
199
  query: str = typer.Argument(
@@ -9,7 +9,7 @@ class EmbedderBase:
9
9
  self._model = model
10
10
  self._vector_dim = vector_dim
11
11
 
12
- async def embed(self, text: str) -> list[float]:
12
+ async def embed(self, text: str | list[str]) -> list[float] | list[list[float]]:
13
13
  raise NotImplementedError(
14
14
  "Embedder is an abstract class. Please implement the embed method in a subclass."
15
15
  )
@@ -1,11 +1,17 @@
1
- from ollama import AsyncClient
1
+ from openai import AsyncOpenAI
2
2
 
3
3
  from haiku.rag.config import Config
4
4
  from haiku.rag.embeddings.base import EmbedderBase
5
5
 
6
6
 
7
7
  class Embedder(EmbedderBase):
8
- async def embed(self, text: str) -> list[float]:
9
- client = AsyncClient(host=Config.OLLAMA_BASE_URL)
10
- res = await client.embeddings(model=self._model, prompt=text)
11
- return list(res["embedding"])
8
+ async def embed(self, text: str | list[str]) -> list[float] | list[list[float]]:
9
+ client = AsyncOpenAI(base_url=f"{Config.OLLAMA_BASE_URL}/v1", api_key="dummy")
10
+ response = await client.embeddings.create(
11
+ model=self._model,
12
+ input=text,
13
+ )
14
+ if isinstance(text, str):
15
+ return response.data[0].embedding
16
+ else:
17
+ return [item.embedding for item in response.data]
@@ -4,10 +4,13 @@ from haiku.rag.embeddings.base import EmbedderBase
4
4
 
5
5
 
6
6
  class Embedder(EmbedderBase):
7
- async def embed(self, text: str) -> list[float]:
7
+ async def embed(self, text: str | list[str]) -> list[float] | list[list[float]]:
8
8
  client = AsyncOpenAI()
9
9
  response = await client.embeddings.create(
10
10
  model=self._model,
11
11
  input=text,
12
12
  )
13
- return response.data[0].embedding
13
+ if isinstance(text, str):
14
+ return response.data[0].embedding
15
+ else:
16
+ return [item.embedding for item in response.data]
@@ -5,7 +5,7 @@ from haiku.rag.embeddings.base import EmbedderBase
5
5
 
6
6
 
7
7
  class Embedder(EmbedderBase):
8
- async def embed(self, text: str) -> list[float]:
8
+ async def embed(self, text: str | list[str]) -> list[float] | list[list[float]]:
9
9
  client = AsyncOpenAI(
10
10
  base_url=f"{Config.VLLM_EMBEDDINGS_BASE_URL}/v1", api_key="dummy"
11
11
  )
@@ -13,4 +13,7 @@ class Embedder(EmbedderBase):
13
13
  model=self._model,
14
14
  input=text,
15
15
  )
16
- return response.data[0].embedding
16
+ if isinstance(text, str):
17
+ return response.data[0].embedding
18
+ else:
19
+ return [item.embedding for item in response.data]
@@ -4,10 +4,14 @@ try:
4
4
  from haiku.rag.embeddings.base import EmbedderBase
5
5
 
6
6
  class Embedder(EmbedderBase):
7
- async def embed(self, text: str) -> list[float]:
7
+ async def embed(self, text: str | list[str]) -> list[float] | list[list[float]]:
8
8
  client = Client()
9
- res = client.embed([text], model=self._model, output_dtype="float")
10
- return res.embeddings[0] # type: ignore[return-value]
9
+ if isinstance(text, str):
10
+ res = client.embed([text], model=self._model, output_dtype="float")
11
+ return res.embeddings[0] # type: ignore[return-value]
12
+ else:
13
+ res = client.embed(text, model=self._model, output_dtype="float")
14
+ return res.embeddings # type: ignore[return-value]
11
15
 
12
16
  except ImportError:
13
17
  pass
haiku/rag/logging.py CHANGED
@@ -3,13 +3,9 @@ import logging
3
3
  from rich.console import Console
4
4
  from rich.logging import RichHandler
5
5
 
6
- logging.basicConfig(level=logging.DEBUG)
7
- logging.getLogger("httpx").setLevel(logging.WARNING)
8
- logging.getLogger("httpcore").setLevel(logging.WARNING)
9
- logging.getLogger("docling").setLevel(logging.WARNING)
10
-
11
6
 
12
7
  def get_logger() -> logging.Logger:
8
+ """Return the library logger configured with a Rich handler."""
13
9
  logger = logging.getLogger("haiku.rag")
14
10
 
15
11
  handler = RichHandler(
@@ -19,11 +15,39 @@ def get_logger() -> logging.Logger:
19
15
  formatter = logging.Formatter("%(message)s")
20
16
  handler.setFormatter(formatter)
21
17
 
22
- logger.setLevel("INFO")
18
+ logger.setLevel(logging.INFO)
23
19
 
24
20
  # Remove any existing handlers to avoid duplicates on reconfiguration
25
21
  for hdlr in logger.handlers[:]:
26
22
  logger.removeHandler(hdlr)
27
23
 
28
24
  logger.addHandler(handler)
25
+ # Do not let messages propagate to the root logger
26
+ logger.propagate = False
27
+ return logger
28
+
29
+
30
+ def configure_cli_logging(level: int = logging.INFO) -> logging.Logger:
31
+ """Configure logging for CLI runs.
32
+
33
+ - Silence ALL non-haiku.rag loggers by detaching root handlers and setting
34
+ their level to ERROR.
35
+ - Attach a Rich handler only to the "haiku.rag" logger.
36
+ - Prevent propagation so only our logger prints in the CLI.
37
+ """
38
+ # Silence root logger completely
39
+ root = logging.getLogger()
40
+ for hdlr in root.handlers[:]:
41
+ root.removeHandler(hdlr)
42
+ root.setLevel(logging.ERROR)
43
+
44
+ # Optionally silence some commonly noisy libraries explicitly as a safeguard
45
+ for noisy in ("httpx", "httpcore", "docling", "urllib3", "asyncio"):
46
+ logging.getLogger(noisy).setLevel(logging.ERROR)
47
+ logging.getLogger(noisy).propagate = False
48
+
49
+ # Configure and return our app logger
50
+ logger = get_logger()
51
+ logger.setLevel(level)
52
+ logger.propagate = False
29
53
  return logger
@@ -154,13 +154,7 @@ class ChunkRepository:
154
154
  """Create chunks and embeddings for a document from DoclingDocument."""
155
155
  chunk_texts = await chunker.chunk(document)
156
156
 
157
- # Generate embeddings in parallel for all chunks
158
- embeddings_tasks = []
159
- for chunk_text in chunk_texts:
160
- embeddings_tasks.append(self.embedder.embed(chunk_text))
161
-
162
- # Wait for all embeddings to complete
163
- embeddings = await asyncio.gather(*embeddings_tasks)
157
+ embeddings = await self.embedder.embed(chunk_texts)
164
158
 
165
159
  # Prepare all chunk records for batch insertion
166
160
  chunk_records = []
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: haiku.rag
3
- Version: 0.7.2
3
+ Version: 0.7.4
4
4
  Summary: Retrieval Augmented Generation (RAG) with LanceDB
5
5
  Author-email: Yiorgis Gozadinos <ggozadinos@gmail.com>
6
6
  License: MIT
@@ -1,21 +1,21 @@
1
1
  haiku/rag/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- haiku/rag/app.py,sha256=GmuZxH7BMutWt8Mdu0RSateRBaKiqXh7Z9tV7cZX6n0,7655
2
+ haiku/rag/app.py,sha256=S19UWA6dxl9NayL9hOZKC5D7fjNat4n0mUOw2PAF9u8,7842
3
3
  haiku/rag/chunker.py,sha256=PVe6ysv8UlacUd4Zb3_8RFWIaWDXnzBAy2VDJ4TaUsE,1555
4
- haiku/rag/cli.py,sha256=UY9Vh5RsIxSCV14eQbNOiwToKmbFAvqTOAnxjieaYBs,6399
4
+ haiku/rag/cli.py,sha256=HqFHU9x2tR1yTR74V3NPndqE4R2Yn-ohASyHp334pAg,8597
5
5
  haiku/rag/client.py,sha256=N4zkWjE9Rsw9YgPvNo83xptHUQR2ognfOnjkoV_w6hc,20999
6
6
  haiku/rag/config.py,sha256=3H41da9BU1R1y2JJHD0cOSErX_VSM1UXA7M2JSOxFXE,1795
7
- haiku/rag/logging.py,sha256=DOQi9QMpQRl8h17Vu4nQh8HxpHdeIu29n8-HZaT3SRQ,786
7
+ haiku/rag/logging.py,sha256=a0ELyeMqb85ebeOTN8OQCTL1PiMWiiV9R_OOH-VZoA8,1665
8
8
  haiku/rag/mcp.py,sha256=bR9Y-Nz-hvjiql20Y0KE0hwNGwyjmPGX8K9d-qmXptY,4683
9
9
  haiku/rag/migration.py,sha256=gWxQwiKo0YulRhogYz4K8N98kHN9LQXIx9FeTmT24v4,10915
10
10
  haiku/rag/monitor.py,sha256=r386nkhdlsU8UECwIuVwnrSlgMk3vNIuUZGNIzkZuec,2770
11
11
  haiku/rag/reader.py,sha256=qkPTMJuQ_o4sK-8zpDl9WFYe_MJ7aL_gUw6rczIpW-g,3274
12
12
  haiku/rag/utils.py,sha256=c8F0ECsFSqvQxzxINAOAnvShoOnJPLsOaNE3JEY2JSc,3230
13
13
  haiku/rag/embeddings/__init__.py,sha256=n7aHW3BxHlpGxU4ze4YYDOsljzFpEep8dwVE2n45JoE,1218
14
- haiku/rag/embeddings/base.py,sha256=NTQvuzbZPu0LBo5wAu3qGyJ4xXUaRAt1fjBO0ygWn_Y,465
15
- haiku/rag/embeddings/ollama.py,sha256=y6-lp0XpbnyIjoOEdtSzMdEVkU5glOwnWQ1FkpUZnpI,370
16
- haiku/rag/embeddings/openai.py,sha256=iA-DewCOSip8PLU_RhEJHFHBle4DtmCCIGNfGs58Wvk,357
17
- haiku/rag/embeddings/vllm.py,sha256=ymNDmpIvDWmkmce5j-TRc_QnJR4qwZCpnYA0tP3ab5o,480
18
- haiku/rag/embeddings/voyageai.py,sha256=0hiRTIqu-bpl-4OaCtMHvWfPdgbrzhnfZJowSV8pLRA,415
14
+ haiku/rag/embeddings/base.py,sha256=BnSviKrlzjv3L0sZJs_T-pxfawd-bcTak-rsX-D2f3A,497
15
+ haiku/rag/embeddings/ollama.py,sha256=LuLlHH6RGoO9_gFCIlbmesuXOj017gTw6z-p8Ez0CfE,595
16
+ haiku/rag/embeddings/openai.py,sha256=fIFCk-jpUtaW0xsnrQnJ824O0UCjaGG2sgvBzREhilc,503
17
+ haiku/rag/embeddings/vllm.py,sha256=vhaUnCn6VMkfSluLhWKtSV-sekFaPsp4pKo2N7-SBCY,626
18
+ haiku/rag/embeddings/voyageai.py,sha256=UW-MW4tJKnPB6Fs2P7A3yt-ZeRm46H9npckchSriPX8,661
19
19
  haiku/rag/qa/__init__.py,sha256=Sl7Kzrg9CuBOcMF01wc1NtQhUNWjJI0MhIHfCWrb8V4,434
20
20
  haiku/rag/qa/agent.py,sha256=15-jMuF08U0uxGdqgQysKMZLr8BUWssI76PtyQ2Ngd8,2912
21
21
  haiku/rag/qa/prompts.py,sha256=xdT4cyrOrAK9UDgVqyev1wHF49jD57Bh40gx2sH4NPI,3341
@@ -30,12 +30,12 @@ haiku/rag/store/models/__init__.py,sha256=s0E72zneGlowvZrFWaNxHYjOAUjgWdLxzdYsnv
30
30
  haiku/rag/store/models/chunk.py,sha256=ZNyTfO6lh3rXWLVYO3TZcitbL4LSUGr42fR6jQQ5iQc,364
31
31
  haiku/rag/store/models/document.py,sha256=zSSpt6pyrMJAIXGQvIcqojcqUzwZnhp3WxVokaWxNRc,396
32
32
  haiku/rag/store/repositories/__init__.py,sha256=Olv5dLfBQINRV3HrsfUpjzkZ7Qm7goEYyMNykgo_DaY,291
33
- haiku/rag/store/repositories/chunk.py,sha256=5S77mGh6pWxPHjaXriJGmvbSOhoNM8tLwygE2GXPlbU,13586
33
+ haiku/rag/store/repositories/chunk.py,sha256=v4y4eh4yIf6zJaWfHxljvnmb12dmvwdinzmxQt8Lvhs,13343
34
34
  haiku/rag/store/repositories/document.py,sha256=lP8Lo82KTP-qwXFRpYZ46WjeAdAsHwZ5pJcrXdz4g0U,6988
35
35
  haiku/rag/store/repositories/settings.py,sha256=dqnAvm-98nQrWpLBbf9QghJw673QD80-iqQhRMP5t0c,5025
36
36
  haiku/rag/store/upgrades/__init__.py,sha256=wUiEoSiHTahvuagx93E4FB07v123AhdbOjwUkPusiIg,14
37
- haiku_rag-0.7.2.dist-info/METADATA,sha256=CLBIBBUYbvBbtynct-n_q7ZVO6cayLa7YUeFivrwEf4,4610
38
- haiku_rag-0.7.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
39
- haiku_rag-0.7.2.dist-info/entry_points.txt,sha256=G1U3nAkNd5YDYd4v0tuYFbriz0i-JheCsFuT9kIoGCI,48
40
- haiku_rag-0.7.2.dist-info/licenses/LICENSE,sha256=eXZrWjSk9PwYFNK9yUczl3oPl95Z4V9UXH7bPN46iPo,1065
41
- haiku_rag-0.7.2.dist-info/RECORD,,
37
+ haiku_rag-0.7.4.dist-info/METADATA,sha256=FBrh4dllbrX9XYaAaPAiq1wLzKe7lBGjk60ICL2oM2Y,4610
38
+ haiku_rag-0.7.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
39
+ haiku_rag-0.7.4.dist-info/entry_points.txt,sha256=G1U3nAkNd5YDYd4v0tuYFbriz0i-JheCsFuT9kIoGCI,48
40
+ haiku_rag-0.7.4.dist-info/licenses/LICENSE,sha256=eXZrWjSk9PwYFNK9yUczl3oPl95Z4V9UXH7bPN46iPo,1065
41
+ haiku_rag-0.7.4.dist-info/RECORD,,