Skip to content

Commit 2cf30fa

Browse files
committed
fix: minor fixes
1 parent 34fab2f commit 2cf30fa

File tree

7 files changed

+517
-37
lines changed

7 files changed

+517
-37
lines changed

api.py

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,29 @@ def get_chroma_client():
118118
# Check if external Chroma server is specified
119119
if CHROMA_HOST:
120120
logger.info(f"Connecting to external Chroma at {CHROMA_HOST}:{CHROMA_PORT}")
121-
client = chromadb.HttpClient(
122-
host=CHROMA_HOST,
123-
port=int(CHROMA_PORT) if CHROMA_PORT else 8000,
124-
settings=Settings(anonymized_telemetry=False),
125-
)
121+
122+
# Use different client init based on whether we're using persistent mode
123+
if USE_PERSISTENT_CHROMA:
124+
logger.info("Using persistent HTTP client mode")
125+
client = chromadb.HttpClient(
126+
host=CHROMA_HOST,
127+
port=int(CHROMA_PORT) if CHROMA_PORT else 8000,
128+
tenant="default_tenant",
129+
settings=Settings(
130+
anonymized_telemetry=False,
131+
allow_reset=True,
132+
),
133+
)
134+
else:
135+
# Standard HTTP client
136+
client = chromadb.HttpClient(
137+
host=CHROMA_HOST,
138+
port=int(CHROMA_PORT) if CHROMA_PORT else 8000,
139+
tenant="default_tenant",
140+
settings=Settings(
141+
anonymized_telemetry=False,
142+
),
143+
)
126144
else:
127145
# Use local persistent Chroma
128146
logger.info(f"Using local Chroma with persistence at {PERSIST_DIRECTORY}")
@@ -131,7 +149,8 @@ def get_chroma_client():
131149
)
132150

133151
# Test connection works
134-
client.heartbeat()
152+
heartbeat = client.heartbeat()
153+
logger.info(f"Chroma connection successful. Heartbeat: {heartbeat}")
135154
return client
136155
except Exception as e:
137156
logger.error(f"Failed to connect to Chroma: {e}")
@@ -203,7 +222,11 @@ async def verify_dependencies():
203222

204223
# Check Chroma connection
205224
try:
206-
count = collection.count()
225+
collection = get_collection()
226+
if collection:
227+
count = collection.count()
228+
else:
229+
errors.append("Could not connect to Chroma collection")
207230
except Exception as e:
208231
errors.append(f"Chroma connection error: {str(e)}")
209232

@@ -235,9 +258,12 @@ async def root():
235258
@app.get("/health")
236259
async def health_check(deps: None = Depends(verify_dependencies)):
237260
"""Health check endpoint that verifies all dependencies are working."""
261+
collection = get_collection()
262+
doc_count = collection.count() if collection else 0
263+
238264
return {
239265
"status": "healthy",
240-
"chroma": {"connected": True, "documents": collection.count()},
266+
"chroma": {"connected": collection is not None, "documents": doc_count},
241267
"openai": {"configured": bool(openai_api_key) or MOCK_EMBEDDINGS},
242268
"mock_mode": MOCK_EMBEDDINGS,
243269
}
@@ -379,6 +405,14 @@ async def agent_query(
379405
logger.info(f"Mock mode overridden to: {use_mock}")
380406

381407
try:
408+
# Get the collection
409+
collection = get_collection()
410+
if collection is None:
411+
raise HTTPException(
412+
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
413+
detail="Vector database is not available. Please check Chroma connection.",
414+
)
415+
382416
# Extract any filter from context
383417
where_filter = {}
384418
if req.filter_type:
@@ -512,6 +546,14 @@ async def get_stats():
512546
logger.info("Stats request received")
513547

514548
try:
549+
# Get the collection
550+
collection = get_collection()
551+
if collection is None:
552+
raise HTTPException(
553+
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
554+
detail="Vector database is not available. Please check Chroma connection.",
555+
)
556+
515557
# Get count of documents in the collection
516558
try:
517559
count = collection.count()

chroma_index/chroma.sqlite3

-292 KB
Binary file not shown.

docker-compose.local.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
version: "3.8"
2-
31
services:
42
# Chroma Vector Database
53
chroma:
64
image: chromadb/chroma:latest
75
volumes:
8-
- ./chroma_index:/chroma/chroma
6+
- ./chroma_index:/chroma/chroma/data
97
environment:
10-
- ALLOW_RESET=true
11-
- ANONYMIZED_TELEMETRY=false
8+
- ALLOW_RESET=True
9+
- ANONYMIZED_TELEMETRY=False
10+
- CHROMA_SERVER_HOST=0.0.0.0
11+
- CHROMA_SERVER_HTTP_PORT=8000
12+
ports:
13+
- "8000:8000"
1214
healthcheck:
1315
test: ["CMD", "curl", "-f", "http://localhost:8000/api/v1/heartbeat"]
14-
interval: 10s
16+
interval: 1s
1517
timeout: 5s
16-
retries: 5
17-
ports:
18-
- "8000:8000" # Map to default port so host apps can connect
18+
retries: 10
1919
networks:
2020
- ignition-network
2121

run_cursor_demo.sh

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/bash
2+
# Script to run a complete demo of the Ignition RAG with Cursor integration
3+
4+
# Colors for output
5+
GREEN='\033[0;32m'
6+
YELLOW='\033[1;33m'
7+
BLUE='\033[0;34m'
8+
RED='\033[0;31m'
9+
NC='\033[0m' # No Color
10+
11+
# Print header
12+
echo -e "${BLUE}==================================================${NC}"
13+
echo -e "${BLUE} Ignition RAG Cursor Demo ${NC}"
14+
echo -e "${BLUE}==================================================${NC}"
15+
16+
# Check if Docker is running
17+
if ! docker info > /dev/null 2>&1; then
18+
echo -e "${RED}Error: Docker is not running. Please start Docker and try again.${NC}"
19+
exit 1
20+
fi
21+
22+
# Check if UV is installed
23+
if ! command -v uv &> /dev/null; then
24+
echo -e "${YELLOW}Warning: UV is not installed. Using regular Python instead.${NC}"
25+
USE_UV=false
26+
else
27+
USE_UV=true
28+
fi
29+
30+
# 1. Start the Chroma and API services
31+
echo -e "${YELLOW}Starting Chroma and API services...${NC}"
32+
./run_local.sh &
33+
34+
# Wait for services to start
35+
echo -e "${YELLOW}Waiting for services to start...${NC}"
36+
sleep 10 # Give some time for services to initialize
37+
38+
# 2. Run the sample indexer to populate the database
39+
echo -e "${YELLOW}Populating the database with sample data...${NC}"
40+
if [ "$USE_UV" = true ]; then
41+
uv run python sample_indexer.py
42+
else
43+
python sample_indexer.py
44+
fi
45+
46+
# 3. Install the Cursor extension
47+
echo -e "${YELLOW}Installing the Cursor extension...${NC}"
48+
./install_cursor_extension.sh
49+
50+
# 4. Show instructions
51+
echo -e "${GREEN}==================================================${NC}"
52+
echo -e "${GREEN} Ignition RAG Cursor Demo is ready! ${NC}"
53+
echo -e "${GREEN}==================================================${NC}"
54+
echo -e ""
55+
echo -e "${BLUE}What's running:${NC}"
56+
echo -e "1. Chroma database at ${BLUE}http://localhost:8000${NC}"
57+
echo -e "2. RAG API service at ${BLUE}http://localhost:8001${NC}"
58+
echo -e "3. Cursor extension has been installed to ${BLUE}~/.cursor/extensions/ignition-rag/${NC}"
59+
echo -e ""
60+
echo -e "${BLUE}Try these sample queries in Cursor:${NC}"
61+
echo -e "- How is the Tank1Level tag configured?"
62+
echo -e "- What is the pump status component?"
63+
echo -e "- How do I set up a tank level indicator in Ignition?"
64+
echo -e "- Explain the pump control view"
65+
echo -e ""
66+
echo -e "${YELLOW}Press Ctrl+C to stop all services${NC}"
67+
68+
# Wait for user to press Ctrl+C
69+
wait

run_local.sh

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@ else
3232
USE_UV=true
3333
fi
3434

35+
# Check for and kill any processes using port 8001
36+
if lsof -Pi :$API_PORT -sTCP:LISTEN -t >/dev/null ; then
37+
echo -e "${YELLOW}Port $API_PORT is already in use. Attempting to kill the process...${NC}"
38+
lsof -Pi :$API_PORT -sTCP:LISTEN -t | xargs kill -9
39+
sleep 1
40+
fi
41+
42+
# Stop and remove existing Chroma containers to avoid conflicts
43+
echo -e "${YELLOW}Cleaning up any existing Chroma containers...${NC}"
44+
docker-compose -f $DOCKER_COMPOSE_FILE down
45+
docker rm -f $(docker ps -a -q --filter "name=chroma") 2>/dev/null || true
46+
47+
# Create the index directory if it doesn't exist
48+
mkdir -p ./chroma_index
49+
chmod -R 777 ./chroma_index
50+
3551
# Start Chroma DB with Docker
3652
echo -e "${YELLOW}Starting Chroma database...${NC}"
3753
docker-compose -f $DOCKER_COMPOSE_FILE up -d chroma
@@ -40,7 +56,7 @@ docker-compose -f $DOCKER_COMPOSE_FILE up -d chroma
4056
echo -e "${YELLOW}Waiting for Chroma to be ready...${NC}"
4157
attempt=0
4258
max_attempts=30
43-
until docker-compose -f $DOCKER_COMPOSE_FILE exec chroma curl -s http://localhost:8000/api/v1/heartbeat > /dev/null; do
59+
until docker-compose -f $DOCKER_COMPOSE_FILE exec -T chroma curl -s http://localhost:8000/api/v1/heartbeat > /dev/null; do
4460
attempt=$((attempt+1))
4561
if [ $attempt -gt $max_attempts ]; then
4662
echo -e "${RED}Error: Chroma failed to start properly.${NC}"
@@ -51,12 +67,23 @@ until docker-compose -f $DOCKER_COMPOSE_FILE exec chroma curl -s http://localhos
5167
echo -n "."
5268
sleep 1
5369
done
54-
echo -e "\n${GREEN}Chroma is ready!${NC}"
70+
71+
# Wait a bit longer for tenant creation
72+
echo -e "${YELLOW}Waiting for tenant initialization (5 seconds)...${NC}"
73+
sleep 5
74+
75+
echo -e "${GREEN}Chroma is ready!${NC}"
76+
77+
# Create default tenant
78+
echo -e "${YELLOW}Creating default tenant...${NC}"
79+
curl -s -X POST http://localhost:8000/api/v1/tenants -H "Content-Type: application/json" -d '{"name":"default_tenant"}' > /dev/null
80+
echo -e "${GREEN}Default tenant created or already exists${NC}"
5581

5682
# Set environment variables for the API
5783
export MOCK_EMBEDDINGS=$USE_MOCK
5884
export CHROMA_HOST=localhost
5985
export CHROMA_PORT=8000
86+
export USE_PERSISTENT_CHROMA=true
6087

6188
# Start the API service
6289
echo -e "${YELLOW}Starting API service on port $API_PORT...${NC}"

0 commit comments

Comments
 (0)