微信扫码
与创始人交个朋友
我要投稿
.01
.02
.03
{
"id": 0,
"vector": [0.01, -0.03, 0.15, ..., -0.08],
"payload": {
"company": "Apple Inc.",
"ticker": "AAPL",
"price": 175.50,
"market_cap": "2.8T",
"industry": "Technology",
"pe_ratio": 28.5
}
}
.04
.05
.06
import pandas as pd
from sentence_transformers import SentenceTransformer
# 加载句子嵌入模型
encoder = SentenceTransformer('all-MiniLM-L6-v2')
# 读取JSON格式的数据
df = pd.read_json('../../stock_data.json')
df = pd.json_normalize(df['stocks'])
df = df[df['company'].notna()]
data = df.to_dict('records')
from qdrant_client import QdrantClient
# 创建内存中的向量数据库
qdrant = QdrantClient(":memory:")
# 创建集合以存储向量数据
qdrant.recreate_collection(
collection_name="top_stocks",
vectors_config=models.VectorParams(
size=encoder.get_sentence_embedding_dimension(),
distance=models.Distance.COSINE
)
)
# 向量化数据并上传至向量数据库
valid_data = [doc for doc in data if isinstance(doc.get("company", ""), str) and doc["company"].strip()]
qdrant.upsert(
collection_name="top_stocks",
points=[
models.PointStruct(
id=idx,
vector=encoder.encode(doc["company"]).tolist(),
payload=doc
) for idx, doc in enumerate(valid_data)
]
)
# 执行查询并获取相似结果
query_prompt = "市值较高的科技公司"
query_vector = encoder.encode(query_prompt).tolist()
search_results = qdrant.search(
collection_name="top_stocks",
query_vector=query_vector,
limit=3,
with_payload=True
)
for result in search_results:
print(f"公司:{result.payload['company']},行业:{result.payload['industry']},市值:{result.payload['market_cap']}")
from openai import OpenAI
client = OpenAI(base_url="http://127.0.0.1:8080/v1", api_key="your_api_key")
completion = client.chat.completions.create(
model="LLaMA_CPP",
messages=[
{"role": "system", "content": "你是股票领域的专家,帮助用户选择股票并回答他们的问题。"},
{"role": "user", "content": "NVIDIA的市值和市盈率是多少?"},
{"role": "assistant", "content": str(search_results)}
]
)
print(completion.choices[0].message["content"])
.07
53AI,企业落地应用大模型首选服务商
产品:大模型应用平台+智能体定制开发+落地咨询服务
承诺:先做场景POC验证,看到效果再签署服务协议。零风险落地应用大模型,已交付160+中大型企业
2024-11-24
解读GraphRAG
2024-11-24
RAGChecker:显著超越RAGAS,一个精细化评估和诊断 RAG 系统的创新框架
2024-11-23
FastRAG半结构化RAG实现思路及OpenAI O1-long COT蒸馏路线思考
2024-11-23
检索增强生成(RAG):解密AI如何融合记忆与搜索
2024-11-23
如何提高RAG系统准确率?12大常见痛点及巧妙解!
2024-11-23
RAG 2.0性能提升:优化索引与召回机制的策略与实践
2024-11-22
RAG技术在实际应用中的挑战与解决方案
2024-11-22
从普通RAG到RAPTOR,10个最新的RAG框架
2024-07-18
2024-05-05
2024-07-09
2024-05-19
2024-07-09
2024-06-20
2024-07-07
2024-07-07
2024-07-08
2024-07-09
2024-11-06
2024-11-06
2024-11-05
2024-11-04
2024-10-27
2024-10-25
2024-10-21
2024-10-21