Skip to content
Merged
181 changes: 181 additions & 0 deletions docs/docs/server/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,104 @@ servers:
security:
- CustomHeaderAuth: []
paths:
/content/search:
post:
operationId: searchContent
tags:
- Content
summary: Search content
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
query:
type: string
description: The search query string.
dataSources:
type: array
items:
type: object
properties:
name:
type: string
type:
type: string
versionLabel:
type: string
required: [name]
description: An array of data sources to search. If not provided, latest version of all data sources will be searched.
limit:
type: integer
minimum: 1
maximum: 100
default: 5
description: The maximum number of results to return.
required:
- query
responses:
200:
description: OK
headers:
Content-Type:
schema:
type: string
example: application/json
content:
application/json:
schema:
$ref: "#/components/schemas/SearchResponse"
400:
description: Bad Request
headers:
Content-Type:
schema:
type: string
example: application/json
content:
application/json:
schema:
$ref: "#/components/responses/BadRequest"
500:
description: Internal Server Error
headers:
Content-Type:
schema:
type: string
example: application/json
content:
application/json:
schema:
$ref: "#/components/responses/InternalServerError"

/content/sources:
get:
operationId: listDataSources
tags:
- Content
summary: List available data sources
description: Returns metadata about all available data sources.
responses:
200:
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/ListDataSourcesResponse"
500:
description: Internal Server Error
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"

/conversations:
post:
operationId: createConversation
tags:
- Conversations
summary: Start new conversation
description: |
Start a new conversation.
Expand All @@ -43,6 +138,8 @@ paths:
/conversations/{conversationId}/messages:
post:
operationId: addMessage
tags:
- Conversations
summary: Add message to the conversation
tags:
- Conversations
Expand Down Expand Up @@ -133,6 +230,8 @@ paths:
# /conversations/{conversationId}:
# get:
# operationId: getConversation
# tags:
# - Conversations
# summary: Get a conversation
# parameters:
# - $ref: "#/components/parameters/conversationId"
Expand All @@ -152,6 +251,8 @@ paths:
/conversations/{conversationId}/messages/{messageId}/rating:
post:
operationId: rateMessage
tags:
- Conversations
summary: Rate message
tags:
- Conversations
Expand All @@ -176,6 +277,8 @@ paths:
/conversations/{conversationId}/messages/{messageId}/comment:
post:
operationId: commentMessage
tags:
- Conversations
summary: Add comment to assistant message
tags:
- Conversations
Expand Down Expand Up @@ -972,6 +1075,68 @@ components:
required: [type, call_id, output, status]
ErrorResponse:
type: object
SearchResponse:
type: object
properties:
results:
type: array
items:
$ref: "#/components/schemas/Chunk"
Chunk:
type: object
properties:
url:
type: string
description: The URL of the search result.
title:
type: string
description: Title of the search result.
text:
type: string
description: Chunk text
metadata:
type: object
properties:
sourceName:
type: string
description: The name of the source.
sourceType:
type: string
tags:
type: array
items:
type: string
additionalProperties: true
ListDataSourcesResponse:
type: object
properties:
dataSources:
type: array
items:
$ref: "#/components/schemas/DataSourceMetadata"
DataSourceMetadata:
type: object
required:
- id
properties:
id:
type: string
description: The name of the data source.
versions:
type: array
items:
type: object
properties:
label:
type: string
description: Version label
isCurrent:
type: boolean
description: Whether this version is current active version.
description: List of versions for this data source.
type:
type: string
description: The type of the data source.
parameters:
conversationId:
name: conversationId
Expand All @@ -987,3 +1152,19 @@ components:
schema:
type: string
description: The unique identifier for a message.

tags:
- name: Content
x-displayName: Search Content
description: Search MongoDB content
- name: Conversations
x-displayName: Conversations
description: Interact with MongoDB Chatbot

x-tagGroups:
- name: Content
tags:
- Content
- name: Conversations
tags:
- Conversations
50 changes: 34 additions & 16 deletions packages/chatbot-server-mongodb-public/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import {
AddCustomDataFunc,
FilterPreviousMessages,
makeDefaultFindVerifiedAnswer,
defaultCreateConversationCustomData,
defaultAddMessageToConversationCustomData,
makeVerifiedAnswerGenerateResponse,
addDefaultCustomData,
ConversationsRouterLocals,
ContentRouterLocals,
addMessageToConversationVerifiedAnswerStream,
responsesVerifiedAnswerStream,
type MakeVerifiedAnswerGenerateResponseParams,
Expand All @@ -34,8 +35,18 @@ import {
import { redactConnectionUri } from "./middleware/redactConnectionUri";
import path from "path";
import express from "express";
import { makeMongoDbPageStore, logger } from "mongodb-rag-core";
import { wrapOpenAI, wrapTraced } from "mongodb-rag-core/braintrust";
import {
makeMongoDbPageStore,
makeMongoDbSearchResultsStore,
logger,
} from "mongodb-rag-core";
import { createAzure, wrapLanguageModel } from "mongodb-rag-core/aiSdk";
import {
makeBraintrustLogger,
BraintrustMiddleware,
wrapOpenAI,
wrapTraced,
} from "mongodb-rag-core/braintrust";
import { AzureOpenAI } from "mongodb-rag-core/openai";
import { MongoClient } from "mongodb-rag-core/mongodb";
import {
Expand All @@ -57,13 +68,9 @@ import {
responsesApiStream,
addMessageToConversationStream,
} from "./processors/generateResponseWithTools";
import {
makeBraintrustLogger,
BraintrustMiddleware,
} from "mongodb-rag-core/braintrust";
import { makeMongoDbScrubbedMessageStore } from "./tracing/scrubbedMessages/MongoDbScrubbedMessageStore";
import { MessageAnalysis } from "./tracing/scrubbedMessages/analyzeMessage";
import { createAzure, wrapLanguageModel } from "mongodb-rag-core/aiSdk";
import { makeFindContentWithMongoDbMetadata } from "./processors/findContentWithMongoDbMetadata";
import { makeMongoDbAssistantSystemPrompt } from "./systemPrompt";
import { makeFetchPageTool } from "./tools/fetchPage";
import { makeCorsOptions } from "./corsOptions";
Expand Down Expand Up @@ -129,6 +136,11 @@ export const embeddedContentStore = makeMongoDbEmbeddedContentStore({
},
});

export const searchResultsStore = makeMongoDbSearchResultsStore({
connectionUri: MONGODB_CONNECTION_URI,
databaseName: MONGODB_DATABASE_NAME,
});

export const verifiedAnswerConfig = {
embeddingModel: OPENAI_VERIFIED_ANSWER_EMBEDDING_DEPLOYMENT,
findNearestNeighborsOptions: {
Expand Down Expand Up @@ -306,7 +318,7 @@ export const makeGenerateResponse = (args?: MakeGenerateResponseParams) =>

export const createConversationCustomDataWithAuthUser: AddCustomDataFunc =
async (req, res) => {
const customData = await defaultCreateConversationCustomData(req, res);
const customData = await addDefaultCustomData(req, res);
if (req.cookies.auth_user) {
customData.authUser = req.cookies.auth_user;
}
Expand Down Expand Up @@ -350,11 +362,20 @@ export async function closeDbConnections() {
logger.info(`Segment logging is ${segmentConfig ? "enabled" : "disabled"}`);

export const config: AppConfig = {
contentRouterConfig: {
findContent: makeFindContentWithMongoDbMetadata({
findContent,
classifierModel: languageModel,
}),
searchResultsStore,
embeddedContentStore,
middleware: [requireValidIpAddress<ContentRouterLocals>(), requireRequestOrigin<ContentRouterLocals>()],
},
conversationsRouterConfig: {
middleware: [
blockGetRequests,
requireValidIpAddress(),
requireRequestOrigin(),
requireValidIpAddress<ConversationsRouterLocals>(),
requireRequestOrigin<ConversationsRouterLocals>(),
useSegmentIds(),
redactConnectionUri(),
cookieParser(),
Expand All @@ -363,10 +384,7 @@ export const config: AppConfig = {
? createConversationCustomDataWithAuthUser
: undefined,
addMessageToConversationCustomData: async (req, res) => {
const defaultCustomData = await defaultAddMessageToConversationCustomData(
req,
res
);
const defaultCustomData = await addDefaultCustomData(req, res);
const customData = {
...defaultCustomData,
};
Expand Down
Loading