MuhammadSaad16 commited on
Commit
39b8bbf
Β·
1 Parent(s): 600f3a7

Add application file

Browse files
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ .env
2
+ backend/.env
API_TEST_RESULTS.txt ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## βœ… API Endpoint Test Results
2
+
3
+ ### 1. Root Endpoint
4
+ **Request:**
5
+ ```bash
6
+ curl.exe -X GET "http://localhost:8000/"
7
+ ```
8
+
9
+ **Response:**
10
+ ```json
11
+ {"message":"RAG Chatbot API"}
12
+ ```
13
+ **Status:** βœ… PASS
14
+
15
+ ---
16
+
17
+ ### 2. Health Check Endpoint
18
+ **Request:**
19
+ ```bash
20
+ curl.exe -X GET "http://localhost:8000/api/health"
21
+ ```
22
+
23
+ **Response:**
24
+ ```json
25
+ {"status":"ok"}
26
+ ```
27
+ **Status:** βœ… PASS
28
+
29
+ ---
30
+
31
+ ### 3. Chat Endpoint (RAG-Powered)
32
+ **Request:**
33
+ ```bash
34
+ curl.exe -X POST "http://localhost:8000/api/chat" \
35
+ -H "Content-Type: application/json" \
36
+ --data "@test_request.json"
37
+ ```
38
+
39
+ **Request Body** (`test_request.json`):
40
+ ```json
41
+ {
42
+ "question": "What is RAG?",
43
+ "user_id": 1
44
+ }
45
+ ```
46
+
47
+ **Response:**
48
+ ```json
49
+ {
50
+ "answer": "RAG, or Retrieval-Augmented Generation, is a machine learning approach that combines retrieval-based techniques with generative models, particularly in the context of natural language processing (NLP). The main idea behind RAG is to enhance the capabilities of generative models (like language models) by integrating them with external knowledge sources or databases.\n\nIn RAG, when a model receives a prompt or query, it first retrieves relevant documents or information from a knowledge base using a retrieval mechanism. Then, it uses this retrieved information to inform and augment its generative response, effectively producing more accurate and contextually relevant answers. This approach allows the model to leverage both broad generative capabilities and specific, factual knowledge, leading to improved performance in tasks like question answering, summarization, and conversational agents.",
51
+ "sources": []
52
+ }
53
+ ```
54
+ **Status:** βœ… PASS
55
+
56
+ **Note:** Sources array is empty because no documents have been ingested yet. To populate the vector database, run:
57
+ ```bash
58
+ python scripts/ingest_content.py
59
+ ```
60
+
61
+ ---
62
+
63
+ ## 🎯 All API Endpoints Working!
64
+
65
+ ### Backend Configuration:
66
+ - **OpenAI API:** βœ… Connected (using gpt-4o)
67
+ - **Database:** βœ… Connected (Neon Postgres)
68
+ - **Qdrant:** βœ… Connected (Qdrant Cloud)
69
+ - **Server:** βœ… Running on http://localhost:8000
70
+
71
+ ### API Documentation:
72
+ Visit http://localhost:8000/docs for interactive API documentation (Swagger UI)
73
+
74
+ ---
75
+
76
+ ## Next Steps:
77
+ 1. βœ… Backend is fully operational
78
+ 2. πŸ“ Ingest documentation content (optional): `python scripts/ingest_content.py`
79
+ 3. πŸš€ Start frontend: `cd physical-ai-humanoid-robotics && npm start`
80
+ 4. πŸ§ͺ Test chat widget on http://localhost:3000
app/services/rag_service.py CHANGED
@@ -2,7 +2,6 @@
2
  import os
3
  import asyncio
4
  from qdrant_client import QdrantClient
5
- from qdrant_client.models import NamedVector
6
  from typing import List
7
 
8
  from app.services.openai_service import OpenAIService
@@ -18,16 +17,16 @@ class RAGService:
18
  async def retrieve_context(self, query: str, top_k: int = 3) -> List[str]:
19
  query_vector = await self.embeddings_service.create_embedding(query)
20
 
21
- # Run synchronous Qdrant query in thread pool
22
  search_result = await asyncio.to_thread(
23
- self.qdrant_client.query_points,
24
  collection_name=self.collection_name,
25
- query=query_vector,
26
  limit=top_k,
27
  with_payload=True
28
  )
29
 
30
- context = [point.payload.get("content", "") for point in search_result.points if point.payload]
31
  return context
32
 
33
  async def generate_response(self, query: str, context: List[str]) -> str:
 
2
  import os
3
  import asyncio
4
  from qdrant_client import QdrantClient
 
5
  from typing import List
6
 
7
  from app.services.openai_service import OpenAIService
 
17
  async def retrieve_context(self, query: str, top_k: int = 3) -> List[str]:
18
  query_vector = await self.embeddings_service.create_embedding(query)
19
 
20
+ # Use search method - compatible with all Qdrant versions
21
  search_result = await asyncio.to_thread(
22
+ self.qdrant_client.search,
23
  collection_name=self.collection_name,
24
+ query_vector=query_vector,
25
  limit=top_k,
26
  with_payload=True
27
  )
28
 
29
+ context = [point.payload.get("content", "") for point in search_result if point.payload]
30
  return context
31
 
32
  async def generate_response(self, query: str, context: List[str]) -> str: