first push
This commit is contained in:
55
backend/tests/test_qdrant.py
Normal file
55
backend/tests/test_qdrant.py
Normal file
@@ -0,0 +1,55 @@
|
||||
import asyncio
|
||||
import random
|
||||
from app.repositories.qdrant_repository import QdrantRepository
|
||||
from qdrant_client.http import models
|
||||
|
||||
async def test_pipeline():
|
||||
print("--- Test de connexion Qdrant ---")
|
||||
repo = QdrantRepository()
|
||||
|
||||
try:
|
||||
# 1. Tester la connexion et initialiser la collection
|
||||
await repo.init_collection(vector_size=1024)
|
||||
|
||||
# 2. Insérer un faux projet pour valider le fonctionnement (Upsert)
|
||||
print("\n[Test] Insertion d'un faux projet indexé...")
|
||||
mock_vector = [random.uniform(-1.0, 1.0) for _ in range(1024)]
|
||||
|
||||
await repo.client.upsert(
|
||||
collection_name=repo.collection_name,
|
||||
points=[
|
||||
models.PointStruct(
|
||||
id=1,
|
||||
vector=mock_vector,
|
||||
payload={
|
||||
"title": "Application E-commerce de test",
|
||||
"description": "Un projet test généré pour valider Qdrant",
|
||||
"git_url": "https://github.com/test/test"
|
||||
}
|
||||
)
|
||||
]
|
||||
)
|
||||
print("[Test] Faux projet inséré.")
|
||||
|
||||
# 3. Tester la recherche vectorielle
|
||||
print("\n[Test] Lancement de la recherche vectorielle...")
|
||||
project_found = await repo.search_similar_project(query_vector=mock_vector)
|
||||
|
||||
if project_found:
|
||||
print(f"🎉 Succès ! Projet trouvé en BDD : {project_found['title']} ({project_found['git_url']})")
|
||||
else:
|
||||
print("❌ Erreur : Aucun projet trouvé alors qu'on vient d'en insérer un.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Échec critique du test : {e}")
|
||||
print("Vérifie que ton conteneur Qdrant est bien lancé et que l'URL dans ton .env est correcte.")
|
||||
|
||||
finally:
|
||||
await repo.close()
|
||||
print("\n--- Fin du test ---")
|
||||
|
||||
if __name__ == "__main__":
|
||||
from dotenv import load_dotenv
|
||||
load_dotenv()
|
||||
|
||||
asyncio.run(test_pipeline())
|
||||
Reference in New Issue
Block a user