Skip to content

Commit 1785c52

Browse files
committed
Fix failing test
1 parent b8dbd6e commit 1785c52

File tree

3 files changed

+167
-186
lines changed

3 files changed

+167
-186
lines changed

_includes/code/python/local.quickstart.import_objects.py

Lines changed: 18 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -4,104 +4,33 @@
44

55
client = weaviate.connect_to_local()
66

7-
print("=== DEBUG: Downloading data ===")
8-
url = "https://raw.githubusercontent.com/weaviate-tutorials/quickstart/main/data/jeopardy_tiny.json"
9-
10-
try:
11-
resp = requests.get(url, timeout=10)
12-
print(f"DEBUG: Status code: {resp.status_code}")
13-
print(f"DEBUG: Content length: {len(resp.content)} bytes")
14-
15-
if resp.status_code != 200:
16-
print(f"DEBUG: HTTP Error - Response: {resp.text}")
17-
raise Exception(f"HTTP {resp.status_code}")
18-
19-
if not resp.text.strip():
20-
print("DEBUG: ERROR - Response is empty!")
21-
raise Exception("Empty response")
22-
23-
print(f"DEBUG: Response preview: {resp.text[:200]}...")
24-
25-
data = json.loads(resp.text)
26-
print(f"DEBUG: ✓ JSON parsed successfully, {len(data)} items")
27-
28-
if data and len(data) > 0:
29-
print(f"DEBUG: First item: {data[0]}")
30-
31-
except Exception as e:
32-
print(f"DEBUG: ✗ Download failed: {e}")
33-
print("DEBUG: Using fallback test data")
34-
data = [
35-
{"Answer": "DNA", "Question": "What carries genetic information?", "Category": "BIOLOGY"},
36-
{"Answer": "Photosynthesis", "Question": "Process plants use to make food?", "Category": "BIOLOGY"},
37-
{"Answer": "Mitochondria", "Question": "Powerhouse of the cell?", "Category": "BIOLOGY"}
38-
]
39-
40-
print("=== DEBUG: Starting batch import ===")
41-
questions = client.collections.get("Question")
42-
43-
if not data:
44-
print("DEBUG: ✗ No data to import")
45-
client.close()
46-
exit(1)
47-
48-
print(f"DEBUG: About to import {len(data)} objects")
7+
resp = requests.get(
8+
"https://raw.githubusercontent.com/weaviate-tutorials/quickstart/main/data/jeopardy_tiny.json"
9+
)
10+
data = json.loads(resp.text)
4911

5012
# highlight-start
51-
successful_imports = 0
52-
failed_imports = 0
13+
questions = client.collections.get("Question")
5314

5415
with questions.batch.fixed_size(batch_size=200) as batch:
55-
for i, item in enumerate(data):
56-
try:
57-
batch.add_object({
58-
"answer": item["Answer"],
59-
"question": item["Question"],
60-
"category": item["Category"],
61-
})
62-
successful_imports += 1
63-
64-
if (i + 1) % 10 == 0:
65-
print(f"DEBUG: Processed {i + 1}/{len(data)} items")
66-
67-
except KeyError as ke:
68-
failed_imports += 1
69-
print(f"DEBUG: ✗ Item {i} missing key {ke}: {item}")
70-
except Exception as e:
71-
failed_imports += 1
72-
print(f"DEBUG: ✗ Error with item {i}: {e}")
73-
16+
for d in data:
17+
batch.add_object(
18+
{
19+
"answer": d["Answer"],
20+
"question": d["Question"],
21+
"category": d["Category"],
22+
}
23+
)
7424
# highlight-end
7525
if batch.number_errors > 10:
76-
print(f"DEBUG: ✗ Too many batch errors: {batch.number_errors}")
26+
print("Batch import stopped due to excessive errors.")
7727
break
7828

79-
print(f"DEBUG: Import attempt completed - Success: {successful_imports}, Failed: {failed_imports}")
80-
8129
failed_objects = questions.batch.failed_objects
8230
if failed_objects:
83-
print(f"DEBUG: ✗ Batch failed objects: {len(failed_objects)}")
84-
if len(failed_objects) > 0:
85-
print(f"DEBUG: First failed: {failed_objects[0]}")
86-
else:
87-
print("DEBUG: ✓ No batch failures")
31+
print(f"Number of failed imports: {len(failed_objects)}")
32+
print(f"First failed object: {failed_objects[0]}")
8833

89-
# Verify import
90-
print("=== DEBUG: Verifying import ===")
91-
try:
92-
aggregate_result = questions.aggregate.over_all(total_count=True)
93-
total_count = aggregate_result.total_count
94-
print(f"DEBUG: ✓ Total objects in collection: {total_count}")
95-
96-
if total_count > 0:
97-
sample_objects = questions.query.fetch_objects(limit=2)
98-
print(f"DEBUG: Sample objects:")
99-
for obj in sample_objects.objects:
100-
print(f" - {obj.properties}")
101-
102-
except Exception as e:
103-
print(f"DEBUG: ✗ Verification error: {e}")
34+
client.close() # Free up resources
35+
# END Import
10436

105-
client.close()
106-
print("DEBUG: Import completed")
107-
# END Import

_includes/code/python/local.quickstart.query.rag.py

Lines changed: 3 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -5,81 +5,15 @@
55

66
questions = client.collections.get("Question")
77

8-
print("=== DEBUG: Getting collection configuration ===")
9-
config = questions.config.get()
10-
print(f"DEBUG: Collection config type: {type(config)}")
11-
print(f"DEBUG: Collection config: {config}")
12-
13-
# Print vector configuration
14-
if hasattr(config, "vector_config"):
15-
print(f"DEBUG: Vector config: {config.vector_config}")
16-
if hasattr(config.vector_config, "vectorizer"):
17-
print(f"DEBUG: Vectorizer: {config.vector_config.vectorizer}")
18-
if hasattr(config.vector_config.vectorizer, "config"):
19-
print(f"DEBUG: Vectorizer config: {config.vector_config.vectorizer.config}")
20-
21-
# Print generative configuration
22-
if hasattr(config, "generative_config"):
23-
print(f"DEBUG: Generative config: {config.generative_config}")
24-
if hasattr(config.generative_config, "generative"):
25-
print(f"DEBUG: Generative: {config.generative_config.generative}")
26-
if hasattr(config.generative_config.generative, "config"):
27-
print(
28-
f"DEBUG: Generative config: {config.generative_config.generative.config}"
29-
)
30-
31-
print("=== DEBUG: Starting RAG query ===")
32-
338
# highlight-start
349
response = questions.generate.near_text(
35-
query="biology",
10+
query="science",
3611
limit=2,
37-
grouped_task="Write a tweet with emojis about these facts.",
12+
grouped_task="Write a tweet with emojis about these facts."
3813
)
3914
# highlight-end
4015

41-
print(f"DEBUG: Response type: {type(response)}")
42-
print(f"DEBUG: Response object: {response}")
43-
print(
44-
f"DEBUG: Response attributes: {[attr for attr in dir(response) if not attr.startswith('_')]}"
45-
)
46-
47-
# Check if response has generative attribute
48-
if hasattr(response, "generative"):
49-
print(f"DEBUG: response.generative type: {type(response.generative)}")
50-
print(f"DEBUG: response.generative value: {response.generative}")
51-
52-
if response.generative is not None:
53-
print(
54-
f"DEBUG: generative attributes: {[attr for attr in dir(response.generative) if not attr.startswith('_')]}"
55-
)
56-
57-
if hasattr(response.generative, "text"):
58-
print(f"DEBUG: Generated text exists: {response.generative.text}")
59-
else:
60-
print("DEBUG: ERROR - response.generative has no 'text' attribute")
61-
else:
62-
print("DEBUG: ERROR - response.generative is None")
63-
else:
64-
print("DEBUG: ERROR - response has no 'generative' attribute")
65-
66-
# Check if there are search results
67-
if hasattr(response, "objects"):
68-
print(f"DEBUG: Number of objects found: {len(response.objects)}")
69-
for i, obj in enumerate(response.objects):
70-
print(f"DEBUG: Object {i+1}: {obj.properties}")
71-
else:
72-
print("DEBUG: No objects found in response")
73-
74-
# Only print the text if it exists
75-
if (
76-
hasattr(response, "generative")
77-
and response.generative is not None
78-
and hasattr(response.generative, "text")
79-
):
80-
print(response.generative.text) # Inspect the generated text
81-
else:
82-
print("ERROR: Cannot access response.generative.text - it's None or doesn't exist")
16+
print(response.generative.text) # Inspect the generated text
8317

8418
client.close() # Free up resources
8519
# END RAG

0 commit comments

Comments
 (0)