diff --git a/backend/endpoints/v1/tools/index.js b/backend/endpoints/v1/tools/index.js index ae3e101..382b425 100644 --- a/backend/endpoints/v1/tools/index.js +++ b/backend/endpoints/v1/tools/index.js @@ -3,12 +3,8 @@ const { Organization } = require("../../../models/organization"); const { OrganizationConnection, } = require("../../../models/organizationConnection"); -const { - OrganizationWorkspace, -} = require("../../../models/organizationWorkspace"); const { Queue } = require("../../../models/queue"); const { RagTest } = require("../../../models/ragTest"); -const { SystemSettings } = require("../../../models/systemSettings"); const { userFromSession, validSessionForUser, @@ -20,12 +16,10 @@ const { const { organizationResetJob, } = require("../../../utils/jobs/organizationResetJob"); -const { OpenAi } = require("../../../utils/openAi"); const { createRagTest } = require("../../../utils/toolHelpers/RagTests/create"); const { workspaceSimilaritySearch, } = require("../../../utils/toolHelpers/workspaceSimilaritySearch"); -const { selectConnector } = require("../../../utils/vectordatabases/providers"); process.env.NODE_ENV === "development" ? require("dotenv").config({ path: `.env.${process.env.NODE_ENV}` }) @@ -218,10 +212,12 @@ function toolEndpoints(app) { id: true, promptText: true, frequencyType: true, - topk: true, + topK: true, lastRun: true, - comparisons: false, - promptVector: false, + comparisons: true, + promptVector: true, + workspace: true, + organization: true, organization_rag_test_runs: { select: { id: true, diff --git a/backend/prisma/migrations/20231018015202_init/migration.sql b/backend/prisma/migrations/20231018015202_init/migration.sql new file mode 100644 index 0000000..ba21d69 --- /dev/null +++ b/backend/prisma/migrations/20231018015202_init/migration.sql @@ -0,0 +1,9 @@ +/* + Warnings: + + - You are about to drop the column `topk` on the `organization_rag_tests` table. All the data in the column will be lost. + +*/ +-- AlterTable +ALTER TABLE "organization_rag_tests" DROP COLUMN "topk", +ADD COLUMN "topK" INTEGER DEFAULT 3; diff --git a/backend/prisma/schema.prisma b/backend/prisma/schema.prisma index f0fedd9..f07aabe 100644 --- a/backend/prisma/schema.prisma +++ b/backend/prisma/schema.prisma @@ -152,7 +152,7 @@ model organization_rag_tests { frequencyType String promptText String? promptVector Float[] - topk Int? @default(3) + topK Int? @default(3) comparisons Json[] lastRun DateTime? createdAt DateTime @default(now()) diff --git a/backend/storage/settings.json b/backend/storage/settings.json index 92a7bed..72d21b9 100644 --- a/backend/storage/settings.json +++ b/backend/storage/settings.json @@ -1551,202 +1551,6 @@ "readonly": false } }, - "organization_rag_tests": { - "slug": "organization_rag_tests", - "table": { - "name": "organization_rag_tests", - "pk": "id", - "verbose": "organization_rag_tests" - }, - "columns": [ - { - "name": "id", - "verbose": "id", - "control": { - "text": true - }, - "type": "integer", - "allowNull": false, - "defaultValue": null, - "listview": { - "show": true - }, - "editview": { - "show": true - } - }, - { - "name": "frequencyType", - "verbose": "frequencyType", - "control": { - "text": true - }, - "type": "text", - "allowNull": false, - "defaultValue": null, - "listview": { - "show": true - }, - "editview": { - "show": true - } - }, - { - "name": "promptText", - "verbose": "promptText", - "control": { - "text": true - }, - "type": "text", - "allowNull": true, - "defaultValue": null, - "listview": { - "show": true - }, - "editview": { - "show": true - } - }, - { - "name": "promptVector", - "verbose": "promptVector", - "control": { - "text": true - }, - "type": "ARRAY", - "allowNull": true, - "defaultValue": null, - "listview": { - "show": true - }, - "editview": { - "show": true - } - }, - { - "name": "topk", - "verbose": "topk", - "control": { - "text": true - }, - "type": "integer", - "allowNull": true, - "defaultValue": "3", - "listview": { - "show": true - }, - "editview": { - "show": true - } - }, - { - "name": "comparisons", - "verbose": "comparisons", - "control": { - "text": true - }, - "type": "ARRAY", - "allowNull": true, - "defaultValue": null, - "listview": { - "show": true - }, - "editview": { - "show": true - } - }, - { - "name": "lastRun", - "verbose": "lastRun", - "control": { - "text": true - }, - "type": "timestamp", - "allowNull": true, - "defaultValue": null, - "listview": { - "show": true - }, - "editview": { - "show": true - } - }, - { - "name": "createdAt", - "verbose": "createdAt", - "control": { - "text": true - }, - "type": "timestamp", - "allowNull": false, - "defaultValue": "CURRENT_TIMESTAMP", - "listview": { - "show": true - }, - "editview": { - "show": true - } - }, - { - "name": "lastUpdatedAt", - "verbose": "lastUpdatedAt", - "control": { - "text": true - }, - "type": "timestamp", - "allowNull": false, - "defaultValue": "CURRENT_TIMESTAMP", - "listview": { - "show": true - }, - "editview": { - "show": true - } - }, - { - "name": "organization_id", - "verbose": "organization_id", - "control": { - "text": true - }, - "type": "integer", - "allowNull": false, - "defaultValue": null, - "listview": { - "show": true - }, - "editview": { - "show": true - } - }, - { - "name": "workspace_id", - "verbose": "workspace_id", - "control": { - "text": true - }, - "type": "integer", - "allowNull": false, - "defaultValue": null, - "listview": { - "show": true - }, - "editview": { - "show": true - } - } - ], - "mainview": { - "show": true - }, - "listview": { - "order": {}, - "page": 25 - }, - "editview": { - "readonly": false - } - }, "organization_rag_test_runs": { "slug": "organization_rag_test_runs", "table": { @@ -1878,5 +1682,201 @@ "editview": { "readonly": false } + }, + "organization_rag_tests": { + "slug": "organization_rag_tests", + "table": { + "name": "organization_rag_tests", + "pk": "id", + "verbose": "organization_rag_tests" + }, + "columns": [ + { + "name": "id", + "verbose": "id", + "control": { + "text": true + }, + "type": "integer", + "allowNull": false, + "defaultValue": null, + "listview": { + "show": true + }, + "editview": { + "show": true + } + }, + { + "name": "frequencyType", + "verbose": "frequencyType", + "control": { + "text": true + }, + "type": "text", + "allowNull": false, + "defaultValue": null, + "listview": { + "show": true + }, + "editview": { + "show": true + } + }, + { + "name": "promptText", + "verbose": "promptText", + "control": { + "text": true + }, + "type": "text", + "allowNull": true, + "defaultValue": null, + "listview": { + "show": true + }, + "editview": { + "show": true + } + }, + { + "name": "promptVector", + "verbose": "promptVector", + "control": { + "text": true + }, + "type": "ARRAY", + "allowNull": true, + "defaultValue": null, + "listview": { + "show": true + }, + "editview": { + "show": true + } + }, + { + "name": "comparisons", + "verbose": "comparisons", + "control": { + "text": true + }, + "type": "ARRAY", + "allowNull": true, + "defaultValue": null, + "listview": { + "show": true + }, + "editview": { + "show": true + } + }, + { + "name": "lastRun", + "verbose": "lastRun", + "control": { + "text": true + }, + "type": "timestamp", + "allowNull": true, + "defaultValue": null, + "listview": { + "show": true + }, + "editview": { + "show": true + } + }, + { + "name": "createdAt", + "verbose": "createdAt", + "control": { + "text": true + }, + "type": "timestamp", + "allowNull": false, + "defaultValue": "CURRENT_TIMESTAMP", + "listview": { + "show": true + }, + "editview": { + "show": true + } + }, + { + "name": "lastUpdatedAt", + "verbose": "lastUpdatedAt", + "control": { + "text": true + }, + "type": "timestamp", + "allowNull": false, + "defaultValue": "CURRENT_TIMESTAMP", + "listview": { + "show": true + }, + "editview": { + "show": true + } + }, + { + "name": "organization_id", + "verbose": "organization_id", + "control": { + "text": true + }, + "type": "integer", + "allowNull": false, + "defaultValue": null, + "listview": { + "show": true + }, + "editview": { + "show": true + } + }, + { + "name": "workspace_id", + "verbose": "workspace_id", + "control": { + "text": true + }, + "type": "integer", + "allowNull": false, + "defaultValue": null, + "listview": { + "show": true + }, + "editview": { + "show": true + } + }, + { + "name": "topK", + "verbose": "topK", + "control": { + "text": true + }, + "type": "integer", + "allowNull": true, + "defaultValue": "3", + "listview": { + "show": true + }, + "editview": { + "show": true + } + } + ], + "mainview": { + "show": true + }, + "listview": { + "order": {}, + "page": 25 + }, + "editview": { + "readonly": false + } } } \ No newline at end of file diff --git a/backend/utils/toolHelpers/RagTests/create.js b/backend/utils/toolHelpers/RagTests/create.js index f723ea2..9e88acc 100644 --- a/backend/utils/toolHelpers/RagTests/create.js +++ b/backend/utils/toolHelpers/RagTests/create.js @@ -54,12 +54,12 @@ async function createRagTest(user, request, response) { return; } - const newRagTest = await RagTest.create( + const { test: newRagTest } = await RagTest.create( { frequencyType: frequency, promptText: promptType === "text" ? prompt : null, promptVector: queryVector, - topk: Number(topK), + topK: Number(topK), comparisons: embeddings, }, organization.id, diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index c1c3b0d..a0e2289 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -28,7 +28,7 @@ const MigrateConnectionView = lazy( () => import('./pages/Tools/MigrateConnection') ); const ResetConnectionView = lazy(() => import('./pages/Tools/ResetConnection')); -const RAGDriftTestingView = lazy(() => import('./pages/Tools/RAGDrift')); +const RAGTestingView = lazy(() => import('./pages/Tools/RAGTesting')); function App() { return ( @@ -90,8 +90,8 @@ function App() { element={} /> } + path="/dashboard/:slug/tools/rag-testing" + element={} /> } /> diff --git a/frontend/src/models/tools.ts b/frontend/src/models/tools.ts index 401b346..d9ece75 100644 --- a/frontend/src/models/tools.ts +++ b/frontend/src/models/tools.ts @@ -1,5 +1,7 @@ import { API_BASE } from '../utils/constants'; import { baseHeaders } from '../utils/request'; +import { IOrganization } from './organization'; +import { IWorkspace } from './workspace'; const Tools = { migrateOrg: async ( @@ -36,7 +38,7 @@ const Tools = { }, ragTests: async ( slug: string - ): Promise<{ ragTests: []; message: null | string }> => { + ): Promise<{ ragTests: IRagTest[]; message: null | string }> => { return fetch(`${API_BASE}/v1/tools/org/${slug}/rag-tests`, { method: 'GET', cache: 'no-cache', @@ -51,7 +53,7 @@ const Tools = { newRAGTest: async ( slug: string, settings: object - ): Promise<{ test: object | null; error: null | string }> => { + ): Promise<{ test: IRagTest | null; error: null | string }> => { return fetch(`${API_BASE}/v1/tools/org/${slug}/rag-tests/create`, { method: 'POST', cache: 'no-cache', @@ -64,6 +66,21 @@ const Tools = { return { test: null, error: e.message }; }); }, + deleteRagTest: async (test: IRagTest): Promise => { + return fetch( + `${API_BASE}/v1/tools/org/${test.organization.slug}/rag-tests/${test.id}`, + { + method: 'DELETE', + cache: 'no-cache', + headers: baseHeaders(), + } + ) + .then((res) => res.ok) + .catch((e) => { + console.error(e); + return false; + }); + }, // Generic Uitls workspaceSimilaritySearch: async ( @@ -96,3 +113,28 @@ const Tools = { }; export default Tools; + +export interface IRagEmbedding { + vectorId: string; + metadata: object; + score: number; +} +export interface IRagTestRun { + id: number; + status: 'running' | 'failed' | 'complete' | 'alert'; + result: object; + createdAt: string; +} +export interface IRagTest { + id: number; + promptText?: string; + promptVector: number[]; + comparisons: IRagEmbedding[]; + frequencyType: 'demand' | 'hourly' | 'daily' | 'weekly' | 'monthly'; + topK: number; + lastRun?: string; + workspace: IWorkspace; + organization: IOrganization; + organization_rag_test_runs: IRagTestRun[]; + createdAt: string; +} diff --git a/frontend/src/pages/Tools/RAGDrift/NewTestForm/PromptInputAndSearchSubmission/index.tsx b/frontend/src/pages/Tools/RAGTesting/NewTestForm/PromptInputAndSearchSubmission/index.tsx similarity index 76% rename from frontend/src/pages/Tools/RAGDrift/NewTestForm/PromptInputAndSearchSubmission/index.tsx rename to frontend/src/pages/Tools/RAGTesting/NewTestForm/PromptInputAndSearchSubmission/index.tsx index 060d2f0..464eb20 100644 --- a/frontend/src/pages/Tools/RAGDrift/NewTestForm/PromptInputAndSearchSubmission/index.tsx +++ b/frontend/src/pages/Tools/RAGTesting/NewTestForm/PromptInputAndSearchSubmission/index.tsx @@ -77,7 +77,7 @@ export default function PromptInputAndSearchSubmission({ required={true} onChange={debouncedInput} rows={8} - className="focus:ring-primary-500 focus:border-primary-500 block w-3/4 rounded-lg border border-gray-300 bg-gray-50 p-2.5 text-sm text-gray-900" + className="focus:ring-primary-500 focus:border-primary-500 block w-full rounded-lg border border-gray-300 bg-gray-50 p-2.5 text-sm text-gray-900" placeholder="ex: 'What is VectorAdmin?' or [0.2,0.81,0.89,...,0.05,0.93,0.91,0.17]" > {!!error && ( @@ -126,7 +126,7 @@ function CurrentSimilaritySearch({ organization, prompt, formData }) { if (!formData || !prompt.input || !workspaceId) return null; if (loading) { return ( -
+

finding top {topK} similar embeddings for {workspaceName}.

@@ -136,14 +136,14 @@ function CurrentSimilaritySearch({ organization, prompt, formData }) { if (error) { return ( -
+

{error}

); } if (similarEmbeddings.length === 0) { -
+

Could not find any similar embeddings in {workspaceName}.

@@ -151,33 +151,35 @@ function CurrentSimilaritySearch({ organization, prompt, formData }) { } return ( -
+

If these results look okay to you - click "Create RAG test" to save this test.

- {similarEmbeddings.map((embedding, i) => { - return ( - - -
-
-

{embedding.vectorId}

-

- Similarity {(embedding.score * 100.0).toFixed(2)}% -

+
+ {similarEmbeddings.map((embedding, i) => { + return ( + + +
+
+

{embedding.vectorId}

+

+ Similarity {(embedding.score * 100.0).toFixed(2)}% +

+
+
+                  {JSON.stringify(embedding.metadata || {}, null, 2)}
+                
-
-                {JSON.stringify(embedding.metadata || {}, null, 2)}
-              
-
- - ); - })} + + ); + })} +