弃用langgrpah更换deepagent
This commit is contained in:
0
src/db/__init__.py
Normal file
0
src/db/__init__.py
Normal file
49
src/db/init_mongodb.py
Normal file
49
src/db/init_mongodb.py
Normal file
@@ -0,0 +1,49 @@
|
||||
import asyncio
|
||||
from motor.motor_asyncio import AsyncIOMotorClient
|
||||
|
||||
from src.core.config import MONGO_URI
|
||||
|
||||
DB_NAME = "fida_mongo"
|
||||
COLLECTION_NAME = "user_persona"
|
||||
|
||||
|
||||
async def init_mongo():
|
||||
client = AsyncIOMotorClient(
|
||||
MONGO_URI,
|
||||
maxPoolSize=50,
|
||||
minPoolSize=5,
|
||||
serverSelectionTimeoutMS=5000
|
||||
)
|
||||
|
||||
db = client[DB_NAME]
|
||||
|
||||
# 查看已有集合
|
||||
collections = await db.list_collection_names()
|
||||
|
||||
if COLLECTION_NAME not in collections:
|
||||
print(f"Creating collection: {COLLECTION_NAME}")
|
||||
await db.create_collection(COLLECTION_NAME)
|
||||
|
||||
collection = db[COLLECTION_NAME]
|
||||
|
||||
# 创建 thread_id 唯一索引
|
||||
print("Creating index: thread_id_unique")
|
||||
await collection.create_index(
|
||||
"thread_id",
|
||||
unique=True,
|
||||
name="thread_id_unique"
|
||||
)
|
||||
|
||||
# 创建 TTL 索引(30天自动删除)
|
||||
print("Creating TTL index: updated_at_ttl")
|
||||
await collection.create_index(
|
||||
"updated_at",
|
||||
expireAfterSeconds=2592000, # 30天
|
||||
name="updated_at_ttl"
|
||||
)
|
||||
|
||||
print("MongoDB initialization completed.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(init_mongo())
|
||||
17
src/db/mongo.py
Normal file
17
src/db/mongo.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from motor.motor_asyncio import AsyncIOMotorClient
|
||||
|
||||
from src.core.config import MONGO_URI
|
||||
|
||||
client = AsyncIOMotorClient(
|
||||
MONGO_URI,
|
||||
maxPoolSize=50,
|
||||
minPoolSize=5,
|
||||
serverSelectionTimeoutMS=5000
|
||||
)
|
||||
|
||||
db = client["fida_mongo"]
|
||||
|
||||
user_persona_collection = db["user_persona"]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user