Skip to content

Commit 1741ae1

Browse files
authored
Merge pull request #6 from czero-cc/develop
refactor: removal of outdated vector endpoints
2 parents d849ad6 + c656f03 commit 1741ae1

6 files changed

Lines changed: 57 additions & 113 deletions

File tree

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ async with CZeroEngineClient() as client:
8989
response = await client.chat(
9090
message="What are the key features?",
9191
use_rag=True,
92-
chunk_limit=5,
9392
similarity_threshold=0.3 # Lower threshold for better recall
9493
)
9594

@@ -99,7 +98,7 @@ async with CZeroEngineClient() as client:
9998
use_rag=False
10099
)
101100
response_with_rag = await client.chat(
102-
message="Explain semantic search",
101+
message="Explain semantic search",
103102
use_rag=True,
104103
similarity_threshold=0.3
105104
)
@@ -122,15 +121,16 @@ results = await client.semantic_search(
122121
# Use direct client for persona interactions
123122
async with CZeroEngineClient() as client:
124123
# Chat with default Gestalt persona
125-
response = await client.chat_with_persona(
124+
response = await client.persona_chat(
126125
persona_id="gestalt-default", # default persona
127126
message="Analyze the implications of AGI"
128127
)
129128

130129
# Or use regular chat (defaults to Gestalt if no persona specified)
131130
response = await client.chat(
132131
message="What are the key features of CZero Engine?",
133-
use_rag=True
132+
use_rag=True,
133+
workspace_filter="workspace-id" # Optional: Filter to specific workspace
134134
)
135135
```
136136

@@ -187,7 +187,7 @@ from langchain_anthropic import ChatAnthropic
187187

188188
# Use multiple LLMs in your workflow
189189
cloud_llm = ChatOpenAI(model="gpt-4") # Or Anthropic, Google, etc.
190-
local_llm = CZeroEngineLLM() # Your local CZero Engine
190+
local_llm = CZeroLLM() # Your local CZero Engine
191191

192192
# The possibilities are endless! 🚀
193193
```
@@ -269,7 +269,6 @@ uv run czero version
269269
| `/api/health` | GET | System health check |
270270
| `/api/chat/send` | POST | LLM chat with optional RAG |
271271
| `/api/vector/search/semantic` | POST | Semantic search with hierarchy |
272-
| `/api/vector/search/similarity` | POST | Find similar chunks |
273272
| `/api/embeddings/generate` | POST | Generate text embeddings |
274273
| `/api/workspaces/create` | POST | Create workspace |
275274
| `/api/workspaces/process` | POST | Process documents |

examples/03_persona_interactions.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,32 @@ async def persona_with_rag():
161161
print("-" * 30)
162162

163163
async with CZeroEngineClient() as client:
164-
# Use persona chat with RAG context
164+
# First, list workspaces to find one with documents
165+
workspaces = await client.list_workspaces()
166+
workspace_id = None
167+
168+
if workspaces.workspaces:
169+
# Use the first available workspace
170+
workspace_id = workspaces.workspaces[0].id
171+
print(f"📁 Using workspace: {workspaces.workspaces[0].name}")
172+
else:
173+
print("⚠️ No workspaces found. Creating a sample workspace...")
174+
# Create a sample workspace if none exist
175+
import tempfile
176+
with tempfile.TemporaryDirectory() as temp_dir:
177+
workspace = await client.create_workspace(
178+
name="Sample Workspace",
179+
path=temp_dir
180+
)
181+
workspace_id = workspace.id
182+
183+
# Use persona chat with RAG context from workspace
165184
print("\n🔍 Asking Gestalt with document context...\n")
166185

167-
# This would use any processed documents in your workspace
168186
response = await client.persona_chat(
169187
persona_id="gestalt-default", # Use real persona
170188
message="Based on the documents, what are the key features of CZero Engine?",
189+
workspace_filter=workspace_id, # Enable RAG with this workspace
171190
max_tokens=100 # Moderate response
172191
)
173192

examples/05_langgraph_integration.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class CZeroEngineLLM(BaseChatModel):
6464
temperature: float = 0.7
6565
base_url: str = "http://localhost:1421"
6666
persona_id: str = "gestalt-default"
67+
workspace_id: Optional[str] = None # For RAG context
6768

6869
class Config:
6970
arbitrary_types_allowed = True
@@ -123,15 +124,17 @@ async def _agenerate(
123124
message=prompt,
124125
system_prompt_template=system_prompt,
125126
max_tokens=self.max_tokens,
126-
temperature=self.temperature
127+
temperature=self.temperature,
128+
workspace_filter=self.workspace_id # Add RAG context if available
127129
)
128130
else:
129131
response = await self.client.chat(
130132
message=prompt,
131133
use_rag=self.use_rag,
132134
system_prompt=system_prompt,
133135
max_tokens=self.max_tokens,
134-
temperature=self.temperature
136+
temperature=self.temperature,
137+
workspace_filter=self.workspace_id # Add RAG context if available
135138
)
136139

137140
message = AIMessage(content=response.response)

src/czero_engine/client.py

Lines changed: 8 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from .models import (
1212
ChatRequest, ChatResponse,
1313
SemanticSearchRequest, SemanticSearchResponse,
14-
SimilaritySearchRequest, RecommendationsRequest,
1514
DocumentsResponse, DocumentMetadata, DocumentFullTextResponse,
1615
EmbeddingRequest, EmbeddingResponse,
1716
WorkspaceCreateRequest, WorkspaceResponse, WorkspaceListResponse, WorkspaceInfo,
@@ -197,72 +196,8 @@ async def semantic_search(
197196
response.raise_for_status()
198197
return SemanticSearchResponse(**response.json())
199198

200-
async def find_similar_chunks(
201-
self,
202-
chunk_id: str,
203-
limit: int = 5,
204-
similarity_threshold: float = 0.5
205-
) -> SemanticSearchResponse:
206-
"""
207-
Find chunks similar to a given chunk ID.
208-
209-
Useful for finding related content or duplicates.
210-
211-
Args:
212-
chunk_id: ID of the reference chunk
213-
limit: Maximum number of results
214-
similarity_threshold: Minimum similarity score
215-
216-
Returns:
217-
SemanticSearchResponse with similar chunks
218-
"""
219-
request = SimilaritySearchRequest(
220-
chunk_id=chunk_id,
221-
limit=limit,
222-
similarity_threshold=similarity_threshold
223-
)
224-
225-
self._log(f"Finding similar to chunk: {chunk_id}")
226-
response = await self.client.post(
227-
f"{self.base_url}/api/vector/search/similarity",
228-
json=request.model_dump()
229-
)
230-
response.raise_for_status()
231-
return SemanticSearchResponse(**response.json())
232-
233-
async def get_recommendations(
234-
self,
235-
positive_chunk_ids: List[str],
236-
negative_chunk_ids: Optional[List[str]] = None,
237-
limit: int = 10
238-
) -> SemanticSearchResponse:
239-
"""
240-
Get content recommendations based on positive/negative examples.
241-
242-
Uses vector math to find content similar to positive examples
243-
and dissimilar to negative examples.
244-
245-
Args:
246-
positive_chunk_ids: Chunk IDs to find similar content to
247-
negative_chunk_ids: Chunk IDs to avoid similarity to
248-
limit: Maximum number of recommendations
249-
250-
Returns:
251-
SemanticSearchResponse with recommended chunks
252-
"""
253-
request = RecommendationsRequest(
254-
positive_chunk_ids=positive_chunk_ids,
255-
negative_chunk_ids=negative_chunk_ids or [],
256-
limit=limit
257-
)
258-
259-
self._log(f"Getting recommendations based on {len(positive_chunk_ids)} positive examples")
260-
response = await self.client.post(
261-
f"{self.base_url}/api/vector/recommendations",
262-
json=request.model_dump()
263-
)
264-
response.raise_for_status()
265-
return SemanticSearchResponse(**response.json())
199+
# Note: find_similar_chunks and get_recommendations methods have been deprecated
200+
# Use semantic_search or hierarchical_retrieve for similar functionality
266201

267202
# ==================== Document Management ====================
268203

@@ -511,12 +446,14 @@ async def persona_chat(
511446
system_prompt_template: Optional[str] = None,
512447
conversation_history: Optional[List[Dict[str, str]]] = None,
513448
max_tokens: int = 1024,
514-
temperature: float = 0.7
449+
temperature: float = 0.7,
450+
workspace_filter: Optional[str] = None
515451
) -> PersonaChatResponse:
516452
"""
517453
Chat with a specific AI persona.
518454
519455
Each persona has its own personality, expertise, and interaction style.
456+
Now supports RAG context when workspace_filter is provided.
520457
521458
Args:
522459
persona_id: ID of the persona to chat with
@@ -526,6 +463,7 @@ async def persona_chat(
526463
conversation_history: Optional conversation history for context
527464
max_tokens: Maximum tokens to generate
528465
temperature: Temperature for generation
466+
workspace_filter: Optional workspace ID for RAG context
529467
530468
Returns:
531469
PersonaChatResponse with persona's response
@@ -537,7 +475,8 @@ async def persona_chat(
537475
system_prompt_template=system_prompt_template,
538476
conversation_history=conversation_history,
539477
max_tokens=max_tokens,
540-
temperature=temperature
478+
temperature=temperature,
479+
workspace_filter=workspace_filter
541480
)
542481

543482
self._log(f"Chatting with persona: {persona_id}")

src/czero_engine/models.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,8 @@ class SemanticSearchResponse(BaseModel):
7070
results: List[SearchResult]
7171

7272

73-
class SimilaritySearchRequest(BaseModel):
74-
"""Request model for /api/vector/search/similarity endpoint."""
75-
chunk_id: str
76-
limit: int = 5
77-
similarity_threshold: float = 0.5
78-
79-
80-
class RecommendationsRequest(BaseModel):
81-
"""Request model for /api/vector/recommendations endpoint."""
82-
positive_chunk_ids: List[str]
83-
negative_chunk_ids: Optional[List[str]] = Field(default_factory=list)
84-
limit: int = 10
73+
# Note: SimilaritySearchRequest and RecommendationsRequest have been deprecated
74+
# Use SemanticSearchRequest or HierarchicalRetrievalRequest instead
8575

8676

8777
# Document Models
@@ -205,6 +195,7 @@ class PersonaChatRequest(BaseModel):
205195
conversation_history: Optional[List[ConversationMessage]] = None
206196
max_tokens: Optional[int] = 1024
207197
temperature: Optional[float] = 0.7
198+
workspace_filter: Optional[str] = None # For RAG context
208199

209200

210201
class PersonaChatResponse(BaseModel):

tests/test_all_endpoints.py

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -215,26 +215,8 @@ async def run_all_tests(self):
215215
)
216216

217217
# Extract chunk_id for similarity search
218-
if search_data and search_data.get("results"):
219-
self.chunk_id = search_data["results"][0]["chunk_id"]
220-
221-
# Similarity search
222-
await self.test_endpoint(
223-
"Similarity Search", "POST", "/api/vector/search/similarity",
224-
{
225-
"chunk_id": self.chunk_id,
226-
"limit": 3
227-
}
228-
)
229-
230-
# Recommendations
231-
await self.test_endpoint(
232-
"Get Recommendations", "POST", "/api/vector/recommendations",
233-
{
234-
"positive_chunk_ids": [self.chunk_id],
235-
"limit": 5
236-
}
237-
)
218+
# Note: Similarity search and recommendations endpoints are deprecated
219+
# The new hierarchical retrieval system replaces these with direct query-based search
238220

239221
# 7. Hierarchical Retrieval
240222
console.print("\n[bold yellow]═══ Hierarchical Retrieval ═══[/bold yellow]")
@@ -274,16 +256,27 @@ async def run_all_tests(self):
274256
if persona_data and persona_data.get("persona_id"):
275257
self.persona_id = persona_data["persona_id"]
276258

277-
# Chat with persona
259+
# Chat with persona (without RAG)
278260
await self.test_endpoint(
279-
"Persona Chat", "POST", "/api/personas/chat",
261+
"Persona Chat (No RAG)", "POST", "/api/personas/chat",
280262
{
281263
"persona_id": self.persona_id,
282264
"message": "Hello, test persona!",
283265
"max_tokens": 100
284266
}
285267
)
286268

269+
# Chat with persona (with RAG)
270+
await self.test_endpoint(
271+
"Persona Chat (With RAG)", "POST", "/api/personas/chat",
272+
{
273+
"persona_id": self.persona_id,
274+
"message": "Based on the test document, what can you tell me?",
275+
"workspace_filter": self.workspace_id,
276+
"max_tokens": 100
277+
}
278+
)
279+
287280
# Delete persona
288281
await self.test_endpoint(
289282
"Delete Persona", "DELETE", f"/api/personas/{self.persona_id}"

0 commit comments

Comments
 (0)