Spaces:
Running
Running
File size: 1,303 Bytes
64a0dc2 7dca6d7 64a0dc2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | """Query the live index from the command line — the retrieval acceptance test.
python scripts/search.py "scaled_dot_product_attention"
python scripts/search.py "how to resize images" --library vision
"""
from __future__ import annotations
import argparse
import sys
from dotenv import load_dotenv
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("query")
parser.add_argument("-k", type=int, default=8)
parser.add_argument("--library", default=None)
args = parser.parse_args()
load_dotenv()
from index.hydrate import hydrate_section
from index.retrieve import retrieve
results = retrieve(args.query, k=args.k, library=args.library, debug=True)
if not results:
print("no results — is the index built?")
return 1
for rank, pointer in enumerate(results, start=1):
anchor = f"#{pointer['anchor']}" if pointer["anchor"] else ""
print(f"{rank}. [{pointer['library']}] {pointer['heading_path']}")
print(f" {pointer['url']}{anchor}")
top = hydrate_section(results[0])
if top:
snippet = " ".join(top["content"].split())[:300]
print(f"\n-- top hit content --\n{snippet}...")
return 0
if __name__ == "__main__":
sys.exit(main())
|