robertolofaro commited on
Commit
7caa2c6
·
verified ·
1 Parent(s): 7f2f944

Delete qa_markdown_qdrant_externalized.py

Browse files
Files changed (1) hide show
  1. qa_markdown_qdrant_externalized.py +0 -60
qa_markdown_qdrant_externalized.py DELETED
@@ -1,60 +0,0 @@
1
- #!/usr/bin/env python3
2
- from qa_common import parse_args, build_prompt, generate_answer, save_result
3
- from langchain_qdrant import QdrantVectorStore
4
- from langchain_huggingface import HuggingFaceEmbeddings
5
- from llama_cpp import Llama
6
- # FIX 1: Import the native client to manage its lifecycle
7
- from qdrant_client import QdrantClient
8
-
9
- # ====================== QDRANT SPECIFIC ======================
10
- QDRANT_PATH = "qdrant_db"
11
- COLLECTION_NAME = "articles"
12
- MODEL_PATH = "articles-Q4_K_M.gguf"
13
-
14
- print("Loading embedding model...")
15
- embeddings = HuggingFaceEmbeddings(
16
- model_name="BAAI/bge-small-en-v1.5",
17
- encode_kwargs={'normalize_embeddings': True}
18
- )
19
-
20
- print("Loading Qdrant vector store...")
21
- # FIX 2: Create the client explicitly
22
- client = QdrantClient(path=QDRANT_PATH)
23
-
24
- # Pass the client directly to the vector store
25
- vectorstore = QdrantVectorStore(
26
- client=client,
27
- collection_name=COLLECTION_NAME,
28
- embedding=embeddings
29
- )
30
-
31
- retriever = vectorstore.as_retriever(search_kwargs={"k": 5})
32
-
33
- print("Loading LLM...")
34
- llm = Llama(model_path=MODEL_PATH, n_ctx=25000, n_threads=8, verbose=False)
35
-
36
-
37
- def get_context(query: str) -> str:
38
- docs = retriever.invoke(query)
39
- return "\n\n".join([
40
- f"[Article: {doc.metadata.get('article_title', 'N/A')}] "
41
- f"{doc.page_content}"
42
- for doc in docs
43
- ])
44
-
45
-
46
- if __name__ == "__main__":
47
- args = parse_args()
48
- query = args.prompt if args.prompt else input("\nQuestion: ")
49
-
50
- print("Retrieving context and generating answer...\n")
51
-
52
- context = get_context(query)
53
- prompt = build_prompt(query, context)
54
- answer = generate_answer(llm, prompt)
55
-
56
- save_result(query, answer, args.output)
57
-
58
- # FIX 3: Close connection explicitly while Python is still fully intact
59
- print("Closing vector store connection...")
60
- client.close()