Skip to content

Commit 9fe5ed5

Browse files
isuniverseok-uaisuniverseok
authored andcommitted
include project_id in scope
Signed-off-by: Arnesh Dadhich <arnesh.dadhich@unifyapps.com>
1 parent 460b915 commit 9fe5ed5

File tree

6 files changed

+31
-11
lines changed

6 files changed

+31
-11
lines changed

src/client/acontext-py/src/acontext/resources/sessions.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,23 +503,29 @@ def search(
503503
*,
504504
query: str,
505505
user_id: str,
506+
project_id: str,
506507
limit: int | None = None,
507508
) -> SessionSearchResult:
508509
"""Search for sessions by semantic similarity to a query string.
509510
510511
Args:
511512
query: The search query text.
512513
user_id: The User ID to search within.
514+
project_id: The Project ID to search within.
513515
limit: Maximum number of results to return (1-100, default 10).
514516
515517
Returns:
516518
SessionSearchResult containing list of matching session UUIDs.
517519
518520
Example:
519-
>>> result = client.sessions.search(query="conversations about authentication", user_id="user_123")
521+
>>> result = client.sessions.search(
522+
... query="conversations about authentication",
523+
... user_id="user_123",
524+
... project_id="proj_456"
525+
... )
520526
>>> for session_id in result.session_ids:
521527
... print(session_id)
522528
"""
523-
params = build_params(query=query, user_id=user_id, limit=limit)
529+
params = build_params(query=query, user_id=user_id, project_id=project_id, limit=limit)
524530
data = self._requester.request("GET", "/sessions/search", params=params or None)
525531
return SessionSearchResult.model_validate(data)

src/client/acontext-ts/src/resources/sessions.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,23 +445,27 @@ export class SessionsAPI {
445445
* @param options - Options for searching sessions.
446446
* @param options.query - The search query text.
447447
* @param options.userId - The User ID to search within.
448+
* @param options.projectId - The Project ID to search within.
448449
* @param options.limit - Maximum number of results to return (1-100, default 10).
449450
* @returns SessionSearchResult containing list of matching session UUIDs.
450451
*
451452
* @example
452453
* const result = await client.sessions.search({
453454
* query: 'conversations about authentication',
454-
* userId: 'user_123'
455+
* userId: 'user_123',
456+
* projectId: 'proj_456'
455457
* });
456458
*/
457459
async search(options: {
458460
query: string;
459461
userId: string;
462+
projectId: string;
460463
limit?: number | null;
461464
}): Promise<{ session_ids: string[] }> {
462465
const params = buildParams({
463466
query: options.query,
464467
user_id: options.userId,
468+
project_id: options.projectId,
465469
limit: options.limit ?? null,
466470
});
467471
const data = await this.requester.request('GET', '/sessions/search', {

src/server/api/go/internal/infra/httpclient/core.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ type SessionSearchResponse struct {
401401
}
402402

403403
// SessionSearch calls the session search endpoint in Python Core
404-
func (c *CoreClient) SessionSearch(ctx context.Context, userID string, query string, limit int) (*SessionSearchResponse, error) {
404+
func (c *CoreClient) SessionSearch(ctx context.Context, userID string, projectID string, query string, limit int) (*SessionSearchResponse, error) {
405405
endpoint := fmt.Sprintf("%s/api/v1/sessions/search", c.BaseURL)
406406

407407
httpReq, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint, nil)
@@ -412,6 +412,7 @@ func (c *CoreClient) SessionSearch(ctx context.Context, userID string, query str
412412
// Add query parameters
413413
q := httpReq.URL.Query()
414414
q.Add("user_id", userID)
415+
q.Add("project_id", projectID)
415416
q.Add("query", query)
416417
q.Add("limit", fmt.Sprintf("%d", limit))
417418
httpReq.URL.RawQuery = q.Encode()

src/server/api/go/internal/modules/handler/session.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -780,9 +780,10 @@ func (h *SessionHandler) PatchConfigs(c *gin.Context) {
780780
}
781781

782782
type SessionSearchReq struct {
783-
Query string `form:"query" json:"query" binding:"required" example:"find conversations about authentication"`
784-
UserID string `form:"user_id" json:"user_id" binding:"required" example:"123e4567-e89b-12d3-a456-426614174000"`
785-
Limit int `form:"limit,default=10" json:"limit" binding:"omitempty,min=1,max=100" example:"10"`
783+
Query string `form:"query" json:"query" binding:"required" example:"find conversations about authentication"`
784+
UserID string `form:"user_id" json:"user_id" binding:"required" example:"123e4567-e89b-12d3-a456-426614174000"`
785+
ProjectID string `form:"project_id" json:"project_id" binding:"required" example:"123e4567-e89b-12d3-a456-426614174001"`
786+
Limit int `form:"limit,default=10" json:"limit" binding:"omitempty,min=1,max=100" example:"10"`
786787
}
787788

788789
// SessionSearch godoc
@@ -792,8 +793,10 @@ type SessionSearchReq struct {
792793
// @Tags session
793794
// @Accept json
794795
// @Produce json
795-
// @Param query query string true "Search query text"
796-
// @Param limit query integer false "Maximum number of results (1-100, default 10)"
796+
// @Param query query string true "Search query text"
797+
// @Param user_id query string true "User ID"
798+
// @Param project_id query string true "Project ID"
799+
// @Param limit query integer false "Maximum number of results (1-100, default 10)"
797800
// @Security BearerAuth
798801
// @Success 200 {object} serializer.Response{data=httpclient.SessionSearchResponse}
799802
// @Router /sessions/search [get]
@@ -809,7 +812,7 @@ func (h *SessionHandler) SessionSearch(c *gin.Context) {
809812
limit = 10
810813
}
811814

812-
result, err := h.coreClient.SessionSearch(c.Request.Context(), req.UserID, req.Query, limit)
815+
result, err := h.coreClient.SessionSearch(c.Request.Context(), req.UserID, req.ProjectID, req.Query, limit)
813816
if err != nil {
814817
c.JSON(http.StatusInternalServerError, serializer.Err(http.StatusInternalServerError, "failed to search sessions", err))
815818
return

src/server/core/acontext_core/service/data/session_search_service.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
async def search_sessions_by_task_query(
1111
db_session: AsyncSession,
1212
user_id: asUUID,
13+
project_id: asUUID,
1314
query: str,
1415
topk: int = 10,
1516
threshold: float = 0.8,
@@ -20,6 +21,7 @@ async def search_sessions_by_task_query(
2021
Args:
2122
db_session: Database session
2223
user_id: User ID to scope the search
24+
project_id: Project ID to scope the search
2325
query: Search query text
2426
topk: Maximum number of results to return
2527
threshold: Cosine distance threshold (lower = more similar)
@@ -41,6 +43,7 @@ async def search_sessions_by_task_query(
4143
FROM tasks t
4244
JOIN sessions s ON t.session_id = s.id
4345
WHERE s.user_id = :user_id
46+
AND s.project_id = :project_id
4447
AND t.embedding IS NOT NULL
4548
AND (t.embedding <=> :query_embedding::vector) < :threshold
4649
GROUP BY t.session_id
@@ -53,6 +56,7 @@ async def search_sessions_by_task_query(
5356
{
5457
"query_embedding": str(query_embedding),
5558
"user_id": str(user_id),
59+
"project_id": str(project_id),
5660
"threshold": threshold,
5761
"topk": topk,
5862
},

src/server/core/routers/session.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,20 @@ class SessionSearchResponse(BaseModel):
3737
@search_router.get("/search")
3838
async def session_search(
3939
user_id: asUUID = Query(..., description="User ID to search within"),
40+
project_id: asUUID = Query(..., description="Project ID to search within"),
4041
query: str = Query(..., description="Search query text"),
4142
limit: int = Query(10, ge=1, le=100, description="Maximum results to return"),
4243
) -> SessionSearchResponse:
4344
"""
4445
Uses vector embeddings on Tasks to find sessions with relevant context.
4546
"""
46-
LOG.info(f"Searching sessions in user {user_id} with query: {query[:50]}...")
47+
LOG.info(f"Searching sessions in project {project_id} for user {user_id} with query: {query[:50]}...")
4748

4849
async with DB_CLIENT.get_session_context() as db_session:
4950
result = await search_sessions_by_task_query(
5051
db_session,
5152
user_id,
53+
project_id,
5254
query,
5355
topk=limit,
5456
)

0 commit comments

Comments
 (0)