rajat5ranjan commited on
Commit
ebdb41f
·
verified ·
1 Parent(s): 14c46c2

Update stock_vector_db.py

Browse files
Files changed (1) hide show
  1. stock_vector_db.py +33 -0
stock_vector_db.py CHANGED
@@ -74,3 +74,36 @@ class HFVectorDB:
74
  st.write("⚠️ No index found, returning empty results")
75
  return []
76
  return self.index.similarity_search(query, k=k)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  st.write("⚠️ No index found, returning empty results")
75
  return []
76
  return self.index.similarity_search(query, k=k)
77
+
78
+
79
+
80
+ def save_top_picks_json(top_picks, date, path="top_picks.jsonl"):
81
+ record = {
82
+ "date": date.isoformat(),
83
+ "top_picks": top_picks
84
+ }
85
+ with open(path, "a") as f:
86
+ f.write(json.dumps(record) + "\n")
87
+ st.write(f"✅ Saved top picks to {path}")
88
+
89
+ def add_top_picks_to_vector_db(vector_db, top_picks, date):
90
+ docs = []
91
+ for pick in top_picks:
92
+ content = (
93
+ f"{pick['company']} ({pick['ticker']}):\n"
94
+ f"Sentiment: {pick['sentiment']}\n"
95
+ f"Critical News: {pick['critical_news']}\n"
96
+ f"Impact: {pick['impact_summary']}\n"
97
+ f"Action: {pick['action']}\n"
98
+ f"Reason: {pick['reason']}"
99
+ )
100
+ metadata = {
101
+ "ticker": pick["ticker"],
102
+ "company": pick["company"],
103
+ "sentiment": pick["sentiment"],
104
+ "action": pick["action"],
105
+ "date": date.isoformat()
106
+ }
107
+ docs.append(Document(page_content=content, metadata=metadata))
108
+ vector_db.add_documents(docs)
109
+ st.write("✅ Added top picks to vector DB")