Skip to content

Commit c4e5f2e

Browse files
committed
fixed:remarks on non-existent personas and handling of chatresponse
1 parent 9fa86f7 commit c4e5f2e

4 files changed

Lines changed: 75 additions & 45 deletions

File tree

examples/02_rag_system.py

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ async def rag_example():
2020
print("\n🚀 RAG System Example")
2121
print("=" * 50)
2222

23+
workspace_id = None
24+
2325
# Step 1: Create knowledge base from documents
2426
print("\n1. Creating Knowledge Base")
2527
print("-" * 30)
@@ -70,49 +72,55 @@ async def rag_example():
7072
chunk_overlap=50
7173
)
7274

75+
workspace_id = result['workspace']['id']
7376
print(f"✅ Created workspace: {result['workspace']['name']}")
74-
print(f" ID: {result['workspace']['id']}")
77+
print(f" ID: {workspace_id}")
7578
print(f" Processed {result['files_processed']} files")
7679
print(f" Created {result['chunks_created']} chunks")
80+
81+
# Important: Give the system time to index the documents
82+
print("\n⏳ Waiting for indexing to complete...")
83+
await asyncio.sleep(5) # Wait 5 seconds for indexing
7784

78-
# Step 2: Demonstrate hierarchical search
79-
print("\n2. Hierarchical Semantic Search")
85+
# Step 2: Verify documents are indexed by searching
86+
print("\n2. Verifying Document Indexing")
8087
print("-" * 30)
8188
async with CZeroEngineClient() as client:
82-
# Search with hierarchy support
83-
results = await client.semantic_search(
84-
query="How does AI and machine learning work?",
89+
# Search for content we just indexed, using workspace filter
90+
test_results = await client.semantic_search(
91+
query="artificial intelligence",
8592
limit=3,
86-
include_hierarchy=True,
87-
hierarchy_level=None # Search all levels
93+
similarity_threshold=0.3, # Low threshold to ensure we find something
94+
workspace_filter=workspace_id # Search only in our workspace
8895
)
8996

90-
print(f"Found {len(results.results)} results with hierarchy:")
91-
for i, res in enumerate(results.results, 1):
92-
print(f"\n {i}. Score: {res.similarity:.3f}")
93-
print(f" {res.content[:100]}...")
94-
if res.parent_chunk:
95-
print(f" ↳ Has parent context")
97+
if test_results.results:
98+
print(f"✅ Found {len(test_results.results)} indexed documents")
99+
for i, res in enumerate(test_results.results, 1):
100+
print(f" {i}. Score: {res.similarity:.3f}")
101+
print(f" {res.content[:100]}...")
102+
else:
103+
print("⚠️ Documents may still be indexing. Continuing with example...")
96104

97105
# Step 3: Use RAG for Q&A
98106
print("\n3. RAG-Enhanced Q&A")
99107
print("-" * 30)
108+
print("Note: RAG searches across all workspaces, not just the one we created.")
100109
async with RAGWorkflow() as rag_workflow:
101110

102-
# Ask questions with RAG
111+
# Ask questions that match our indexed documents
103112
questions = [
104-
"What is CZero Engine and what are its main features?",
113+
"What is artificial intelligence and machine learning?",
105114
"How does semantic search work?",
106-
"What's the difference between AI, machine learning, and deep learning?",
107-
"Does CZero Engine support GPU acceleration?"
115+
"What features does CZero Engine provide?"
108116
]
109117

110118
for i, question in enumerate(questions, 1):
111119
print(f"\n📝 Q{i}: {question}")
112120
response = await rag_workflow.ask(
113121
question=question,
114122
chunk_limit=3,
115-
similarity_threshold=0.5
123+
similarity_threshold=0.3 # Lower threshold to be more inclusive
116124
)
117125
print(f"💡 A{i}: {response.response[:250]}...")
118126

@@ -124,7 +132,7 @@ async def rag_example():
124132
# Step 4: Compare with and without RAG
125133
print("\n4. RAG vs Non-RAG Comparison")
126134
print("-" * 30)
127-
comparison_q = "What document processing features does CZero Engine provide?"
135+
comparison_q = "What is machine learning and how does it relate to AI?"
128136

129137
async with RAGWorkflow() as rag_workflow:
130138
comparison = await rag_workflow.compare_with_without_rag(
@@ -133,28 +141,31 @@ async def rag_example():
133141

134142
print(f"\n🤔 Question: {comparison_q}")
135143
print("\n❌ Without RAG (generic response):")
136-
print(f" {comparison['without_rag'][:200]}...")
144+
print(f" {comparison['without_rag'].response[:200]}...")
137145
print("\n✅ With RAG (context-aware):")
138-
print(f" {comparison['with_rag'][:200]}...")
146+
print(f" {comparison['with_rag'].response[:200]}...")
139147
print(f"\n📊 Statistics:")
140-
print(f" Context chunks used: {comparison['chunks_used']}")
148+
chunks_used = len(comparison['with_rag'].context_used) if comparison['with_rag'].context_used else 0
149+
print(f" Context chunks used: {chunks_used}")
141150
print(f" Improvement: More specific and accurate with RAG")
142151

143152
# Step 5: Find similar content
144153
print("\n5. Similarity Search")
145154
print("-" * 30)
146155
async with CZeroEngineClient() as client:
147-
# Get all chunks first
156+
# Search in our workspace for semantic search content
148157
search_res = await client.semantic_search(
149158
query="semantic search",
150-
limit=1
159+
limit=1,
160+
workspace_filter=workspace_id
151161
)
152162

153163
if search_res.results:
154164
chunk_id = search_res.results[0].chunk_id
155165
similar = await client.similarity_search(
156166
chunk_id=chunk_id,
157-
limit=3
167+
limit=3,
168+
similarity_threshold=0.3 # Lower threshold
158169
)
159170

160171
print(f"Content similar to chunk '{chunk_id[:20]}...':\n")

src/czero_engine/client.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
SimilaritySearchRequest, RecommendationsRequest,
1515
DocumentsResponse, DocumentMetadata,
1616
EmbeddingRequest, EmbeddingResponse,
17-
WorkspaceCreateRequest, WorkspaceResponse,
17+
WorkspaceCreateRequest, WorkspaceResponse, WorkspaceListResponse, WorkspaceInfo,
1818
ProcessFilesRequest, ProcessFilesResponse, ProcessingConfig,
1919
PersonaListResponse, PersonaChatRequest, PersonaChatResponse,
2020
HealthResponse,
@@ -99,7 +99,8 @@ async def chat(
9999
temperature: float = 0.7,
100100
similarity_threshold: float = 0.7,
101101
chunk_limit: int = 5,
102-
use_web_search: bool = False
102+
use_web_search: bool = False,
103+
workspace_filter: Optional[str] = None
103104
) -> ChatResponse:
104105
"""
105106
Send a chat message to CZero Engine LLM with optional RAG.
@@ -117,6 +118,7 @@ async def chat(
117118
similarity_threshold: Minimum similarity for RAG chunks
118119
chunk_limit: Maximum number of context chunks to retrieve
119120
use_web_search: Whether to enable web search (if available)
121+
workspace_filter: Optional workspace ID to filter RAG context
120122
121123
Returns:
122124
ChatResponse with generated text and optional context chunks
@@ -132,7 +134,8 @@ async def chat(
132134
use_web_search=use_web_search,
133135
system_prompt=system_prompt,
134136
max_tokens=max_tokens,
135-
temperature=temperature
137+
temperature=temperature,
138+
workspace_filter=workspace_filter
136139
)
137140

138141
self._log(f"Sending chat request (RAG: {use_rag})...")
@@ -341,6 +344,20 @@ async def create_workspace(
341344
response.raise_for_status()
342345
return WorkspaceResponse(**response.json())
343346

347+
async def list_workspaces(self) -> WorkspaceListResponse:
348+
"""
349+
List all available workspaces.
350+
351+
Returns a list of workspaces with their IDs, names, paths, and status.
352+
353+
Returns:
354+
WorkspaceListResponse containing list of WorkspaceInfo objects
355+
"""
356+
self._log("Listing workspaces...")
357+
response = await self.client.get(f"{self.base_url}/api/workspaces")
358+
response.raise_for_status()
359+
return WorkspaceListResponse(**response.json())
360+
344361
async def process_files(
345362
self,
346363
workspace_id: str,

src/czero_engine/models.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class ChatRequest(BaseModel):
2222
system_prompt: Optional[str] = None
2323
max_tokens: Optional[int] = 1024
2424
temperature: Optional[float] = 0.7
25+
workspace_filter: Optional[str] = None
2526

2627

2728
class ContextChunk(BaseModel):
@@ -131,6 +132,22 @@ class WorkspaceResponse(BaseModel):
131132
created_at: str
132133

133134

135+
class WorkspaceInfo(BaseModel):
136+
"""Information about a workspace."""
137+
id: str
138+
name: str
139+
path: str
140+
description: Optional[str] = None
141+
status: str
142+
created_at: str
143+
updated_at: str
144+
145+
146+
class WorkspaceListResponse(BaseModel):
147+
"""Response model for /api/workspaces endpoint."""
148+
workspaces: List[WorkspaceInfo]
149+
150+
134151
class ProcessingConfig(BaseModel):
135152
"""Configuration for file processing."""
136153
chunk_size: Optional[int] = 1000

src/czero_engine/workflows/persona_workflow.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ class PersonaWorkflow:
2828
Workflow for interacting with AI personas in CZero Engine.
2929
3030
Personas provide specialized interaction styles and expertise:
31-
- Gestalt: Adaptive general assistant
32-
- Sage: Research and analysis expert
33-
- Pioneer: Innovation and creative solutions
31+
- Gestalt: General AI assistant (default persona)
3432
3533
Each persona maintains conversation context for coherent dialogue.
3634
"""
@@ -409,19 +407,6 @@ async def example_personas():
409407
"Can you help me understand semantic search?"
410408
)
411409

412-
# Switch to Sage persona
413-
await workflow.select_persona("sage")
414-
response = await workflow.chat(
415-
"What are the philosophical implications of AI?"
416-
)
417-
418-
# Multi-persona discussion
419-
discussion = await workflow.multi_persona_discussion(
420-
topic="The future of human-AI collaboration",
421-
persona_ids=["gestalt-default", "sage", "pioneer"],
422-
rounds=2
423-
)
424-
425410
# Compare persona responses
426411
comparison = await workflow.persona_comparison(
427412
"How should we approach learning new technologies?"

0 commit comments

Comments
 (0)