Skip to content
Merged

Dev #209

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions run_rag_verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,28 @@ def build_question_command(
argv.append(prompt)
return argv


def build_builder_command(
*,
builder: Path,
index_key: str,
pdf_dir: Path,
chunks_dir: Path,
index_dir: Path,
) -> list[str]:
"""Construct the lc_build_index command for the verification run."""

return [
*script_base_command(builder),
index_key,
"--input-dir",
str(pdf_dir),
"--chunks-dir",
str(chunks_dir),
"--index-dir",
str(index_dir),
]


def build_builder_command(
*,
Expand Down Expand Up @@ -873,6 +895,7 @@ def _append_flag(script_path: Path, args: list[str], candidates: list[str], valu

if not use_multi:
base_args: List[str] = []

_append_flag(asker, base_args, ["--key"], index_key)
_append_flag(asker, base_args, ["--index-dir", "--index"], str(index_dir))
_append_flag(asker, base_args, ["--chunks-dir"], str(chunks_dir))
Expand All @@ -888,6 +911,7 @@ def _append_flag(script_path: Path, args: list[str], candidates: list[str], valu
command.extend([topk_flag, str(topk)])
else:
base_args: list[str] = []

_append_flag(multi, base_args, ["--key", "-k"], index_key)
_append_flag(multi, base_args, ["--index-dir", "--index"], str(index_dir))

Expand Down
18 changes: 14 additions & 4 deletions src/langchain/lc_ask.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

from src.langchain.retriever_factory import make_retriever
from src.langchain.trace import configure_emitter

_FAISS_DIR_PATTERN = re.compile(r"^faiss_(?P<key>.+?)__(?P<embed>.+)$")


Expand All @@ -53,6 +54,9 @@ def _infer_key_from_faiss_dir(path: Path) -> str | None:
MODES_REQUIRING_CHUNKS = {"bm25", "hybrid", "parent", "hybrid+compression"}


ROOT = project_root


def _resolve_paths(
key: str,
embed_model: str,
Expand Down Expand Up @@ -248,7 +252,6 @@ def main():
help="Question to ask (overrides positional QUESTION)",
)
parser.add_argument("--json", dest="json_path", help="JSON job file containing 'question'")

key_group = parser.add_mutually_exclusive_group(required=True)
key_group.add_argument("--key", help="collection key used at index time")
key_group.add_argument(
Expand All @@ -257,6 +260,7 @@ def main():

help="Path to FAISS index directory (faiss_<key>__<embed_model>)",
)

parser.add_argument("--embed-model", default="BAAI/bge-small-en-v1.5")

parser.add_argument(
Expand Down Expand Up @@ -330,7 +334,6 @@ def main():
index_dir = Path(args.index_dir).expanduser()

docs: list[Document] | None = None

key_safe: str | None = _fs_safe(args.key) if args.key else None

key_arg = args.key
Expand All @@ -343,11 +346,15 @@ def main():
)

# Prefer a repacked/merged index if available

faiss_dir: Path | None = None
expected_chunks: Path | None = None

for cand in (repacked_dir, base_dir):
if (cand / "index.faiss").exists():
faiss_dir = cand
break

if args.index_path:
if args.index_path:
faiss_dir = Path(args.index_path).expanduser()
if not faiss_dir.exists():
raise SystemExit(f"[lc_ask] FAISS dir not found: {faiss_dir}")
Comment on lines +357 to 360

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P0] Repair mis-indented lc_ask branch causing SyntaxError

The refactor around the index resolution block left if args.index_path: indented with three spaces while the surrounding function uses four. Python treats this as an inconsistent unindent and refuses to compile the module (IndentationError: unindent does not match any outer indentation level). Importing or running lc_ask.py now crashes before any logic executes, so the CLI is broken until the block is properly re-indented.

Useful? React with 👍 / 👎.

Expand Down Expand Up @@ -390,9 +397,11 @@ def main():
f" • Or rebuild the index: python src/langchain/lc_build_index.py {args.key}"
)


if faiss_dir is None:
raise SystemExit("[lc_ask] Unable to resolve FAISS directory")


chunks_path = _locate_chunks_file(
explicit_path=args.chunks_file,
chunks_dir=chunks_dir,
Expand All @@ -402,6 +411,7 @@ def main():
if chunks_path is not None:
docs = _load_chunks_jsonl(chunks_path)


elif args.mode in MODES_REQUIRING_CHUNKS:
raise SystemExit(
f"[lc_ask] chunks not found: {expected_chunks} – run lc_build_index for KEY={args.key}"
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test_run_rag_verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def test_build_builder_command_targets_pdf_and_chunks(tmp_path: Path) -> None:
index_dir=index_dir,
)


assert command[:2] == [sys.executable, str(builder)]

assert command[0] == sys.executable
assert command[1:3] == ["-m", "src.langchain.lc_build_index"]
assert "--input-dir" in command
Expand Down Expand Up @@ -81,6 +84,7 @@ def test_build_question_invocation_for_asker_uses_key_and_index(tmp_path: Path)
)

assert route == "asker"

assert command[0] == sys.executable
assert command[1:3] == ["-m", "src.langchain.lc_ask"]
assert "--key" in command
Expand Down Expand Up @@ -115,6 +119,7 @@ def test_build_question_invocation_for_multi_agent_omits_legacy_subcommand(
)

assert route == "multi"

assert command[0] == sys.executable
assert command[1:3] == ["-m", "src.cli.multi_agent"]
assert "ask" not in command
Expand Down Expand Up @@ -191,3 +196,4 @@ def main() -> None:
flag = determine_flag(script, ["--index", "--index-dir"])

assert flag == "--index-dir"

Loading