微信扫码
与创始人交个朋友
我要投稿
.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-05
15种典型RAG框架:卡内基梅隆大学最新RAG综述
2024-11-05
Claude发布新的RAG方法 --- 通过上下文嵌入与BM25结合显著降低数据块检索失败率
2024-11-05
【大模型】深度解析:智能体如何突破 RAG 的三大技术瓶颈
2024-11-05
RAG 系统的分块难题:小型语言模型如何找到最佳断点?
2024-11-05
Adaptive-RAG:通过问题复杂性学习自适应检索增强LLM
2024-11-05
打造自己的RAG解析大模型:Labelme版面标注并顺利完成训练
2024-11-04
实操|如何优雅的实现RAG与GraphRAG应用中的知识文档增量更新?
2024-11-04
DSPy还能整RAG的活?LeReT: 用强化学习实现LLM智能检索
2024-07-18
2024-07-09
2024-07-09
2024-05-19
2024-05-05
2024-07-07
2024-07-07
2024-06-20
2024-07-08
2024-07-09
2024-11-05
2024-11-04
2024-10-27
2024-10-25
2024-10-21
2024-10-21
2024-10-15
2024-10-15