Skip to content

Commit

Permalink
Tj202/pr views (#40)
Browse files Browse the repository at this point in the history
* Adding notice

* Removed wrong notice

* Adding analytics view

* minor changes

* updating view to use a single GROUP BY

* Creating views in the keyspace given now

---------

Co-authored-by: Glenn Galvizo <[email protected]>
  • Loading branch information
TJ202 and glennga authored Jan 27, 2025
1 parent eea29bd commit 75bdf79
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 11 deletions.
6 changes: 3 additions & 3 deletions docs/source/guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ Agent analysts will follow this workflow:
For logs stored locally, you can find them in the :file:`./agent-activity` directory.
*We recommend the former, as it allows for easy ad-hoc analysis through Couchbase Query and/or Couchbase Analytics.*

2. **Log Transformations**: For users with Couchbase Analytics enabled, we provide four views (expressed as
Couchbase Analytics UDFs) to help you get started with conversational-based agents.
All UDFs below belong to the scope :file:`agent_activity`.
2. **Log Transformations**: For users with Couchbase Analytics enabled, we provide the following views (expressed as
Couchbase Analytics Views) to help you get started with conversational-based agents.
All Views below belong to the scope :file:`agent_activity`.

.. admonition:: Sessions ``(sid, start_t, vid, msgs)``

Expand Down
3 changes: 1 addition & 2 deletions libs/agentc_core/agentc_core/analytics/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ def create_analytics_udfs(cluster: couchbase.cluster.Cluster, bucket: str) -> No
with open(ddl_file, "r") as fp:
raw_ddl_string = fp.read()
ddl_string = (
raw_ddl_string.replace("[ANALYTICS?]", "ANALYTICS")
.replace("[BUCKET_NAME]", bucket)
raw_ddl_string.replace("[BUCKET_NAME]", bucket)
.replace("[SCOPE_NAME]", DEFAULT_AUDIT_SCOPE)
.replace("[LOG_COLLECTION_NAME]", DEFAULT_AUDIT_COLLECTION)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE OR REPLACE ANALYTICS VIEW Sessions AS
CREATE OR REPLACE ANALYTICS VIEW `[BUCKET_NAME]`.`[SCOPE_NAME]`.Sessions AS
WITH
DeDuplicatedLogs AS (
FROM
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- Note: all_sessions.sqlpp should be run before this script.
-- TODO (GLENN): The purpose of this view is to aid in using Ragas, but we should use the raw_logs instead.
CREATE OR REPLACE ANALYTICS VIEW LatestMessages AS
CREATE OR REPLACE ANALYTICS VIEW `[BUCKET_NAME]`.`[SCOPE_NAME]`.LatestMessages AS
WITH LatestGenerations AS (
FROM
`[BUCKET_NAME]`.`[SCOPE_NAME]`.`[LOG_COLLECTION_NAME]` AS s
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
-- Note: all_sessions.sqlpp should be run before this script.
CREATE OR REPLACE [ANALYTICS?] FUNCTION
CREATE OR REPLACE ANALYTICS FUNCTION
`[BUCKET_NAME]`.`[SCOPE_NAME]`.LastSession () {
(
FROM
`[BUCKET_NAME]`.`[SCOPE_NAME]`.Sessions() AS s
`[BUCKET_NAME]`.`[SCOPE_NAME]`.Sessions AS s
SELECT VALUE
s.sid
ORDER BY
Expand Down
11 changes: 11 additions & 0 deletions libs/agentc_core/agentc_core/analytics/ddls/llm_generations.sqlpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CREATE OR REPLACE ANALYTICS VIEW LLMGenerations AS
SELECT
session,
grouping_id,
( FROM g gi SELECT VALUE gi.rl ) AS generation
FROM
`[BUCKET_NAME]`.`[SCOPE_NAME]`.`[LOG_COLLECTION_NAME]` AS rl
GROUP BY
rl.session AS session,
rl.`grouping` AS grouping_id
GROUP AS g;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Note: all_sessions.sqlpp should be run before this script.
CREATE OR REPLACE ANALYTICS VIEW ToolCalls AS
CREATE OR REPLACE ANALYTICS VIEW `[BUCKET_NAME]`.`[SCOPE_NAME]`.ToolCalls AS
FROM
-- The tool calls our LLM has authored.
Sessions AS s1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Note: all_sessions.sqlpp should be run before this script.
CREATE OR REPLACE ANALYTICS VIEW Walks AS
CREATE OR REPLACE ANALYTICS VIEW `[BUCKET_NAME]`.`[SCOPE_NAME]`.Walks AS
FROM
Sessions AS s,
s.msgs AS msg
Expand Down

0 comments on commit 75bdf79

Please sign in to comment.