Skip to main content

mongodb-rag-core

Interfaces

Type Aliases

DatabaseConnection

Ƭ DatabaseConnection: Object

Type declaration

NameType
close(force?: boolean) => Promise<void>
drop() => Promise<void>

Defined in

packages/mongodb-rag-core/src/DatabaseConnection.ts:1


EmbedArgs

Ƭ EmbedArgs: Object

Type declaration

NameTypeDescription
textstringThe text to embed.

Defined in

packages/mongodb-rag-core/src/Embedder.ts:1


EmbedResult

Ƭ EmbedResult: Object

Type declaration

NameTypeDescription
embeddingnumber[]Vector embedding of the text.

Defined in

packages/mongodb-rag-core/src/Embedder.ts:8


EmbeddedContentStore

Ƭ EmbeddedContentStore: VectorStore<EmbeddedContent> & { close?: () => Promise<void> ; deleteEmbeddedContent: (args: { page: Page }) => Promise<void> ; loadEmbeddedContent: (args: { page: Page }) => Promise<EmbeddedContent[]> ; updateEmbeddedContent: (args: { embeddedContent: EmbeddedContent[] ; page: Page }) => Promise<void> }

Data store of the embedded content.

Defined in

packages/mongodb-rag-core/src/EmbeddedContent.ts:60


Embedder

Ƭ Embedder: Object

Takes a string of text and returns an array of numbers representing the vector embedding of the text.

Type declaration

NameType
embed(args: EmbedArgs) => Promise<EmbedResult>

Defined in

packages/mongodb-rag-core/src/Embedder.ts:19


FindNearestNeighborsOptions

Ƭ FindNearestNeighborsOptions: Object

Options for performing a nearest-neighbor search.

Type declaration

NameTypeDescription
filterRecord<string, unknown>Search filter expression.
indexNamestringThe name of the index to use.
knumberThe number of nearest neighbors to return.
minScorenumberThe minimum nearest-neighbor score threshold between 0-1.
numCandidatesnumberNumber of nearest neighbors to use during the search. Value must be less than or equal to 10000. You can't specify a number less than the number of documents to return (k).
pathstringThe keypath to the field with the vector data to use.

Defined in

packages/mongodb-rag-core/src/VectorStore.ts:21


LoadPagesArgs

Ƭ LoadPagesArgs<QueryShape>: Object

Type parameters

NameType
QueryShapeunknown

Type declaration

NameTypeDescription
query?QueryShapeA custom query to refine the pages to load.
sources?string[]The names of the sources to load pages from. If undefined, loads available pages from all sources.
updated?DateIf specified, refines the query to load pages with an updated date later or equal to the given date.
urls?string[]If specified, refines the query to only load pages where the url is included in the list.

Defined in

packages/mongodb-rag-core/src/Page.ts:61


MakeLangChainEmbedderParams

Ƭ MakeLangChainEmbedderParams: Object

Type declaration

NameTypeDescription
langChainEmbeddingsEmbeddingsLangChain.js Embeddings instance. You can configure things like caching and retry behavior in the Embeddings instance.

Defined in

packages/mongodb-rag-core/src/LangChainEmbedder.ts:3


MakeOpenAiEmbedderArgs

Ƭ MakeOpenAiEmbedderArgs: Object

Type declaration

NameTypeDescription
backoffOptions?BackoffOptionsOptions used for automatic retry (usually due to rate limiting).
deploymentstringThe deployment key.
openAiClientOpenAIClientThe OpenAI client.

Defined in

packages/mongodb-rag-core/src/OpenAiEmbedder.ts:7


MakeTypeChatJsonTranslateFuncArgs

Ƭ MakeTypeChatJsonTranslateFuncArgs: Object

Type declaration

NameTypeDescription
azureOpenAiServiceConfigAzureOpenAiServiceConfigSettings for using the Azure service.
numRetries?numberNumber of times to retry the query preprocessor if it fails.
retryDelayMs?numberDelay between retries in milliseconds.
schemastringThe text of a .d.ts that would inform the schema.
schemaNamestringThe name of the TypeChat schema or interface.

Defined in

packages/mongodb-rag-core/src/TypeChatJsonTranslateFunc.ts:11


MongoDbPageStore

Ƭ MongoDbPageStore: DatabaseConnection & Omit<PageStore, "loadPages"> & { queryType: "mongodb" ; loadPages: (args?: LoadPagesArgs<Filter<PersistedPage>>) => Promise<PersistedPage[]> }

Defined in

packages/mongodb-rag-core/src/MongoDbPageStore.ts:10


Page

Ƭ Page: Object

Represents a page from a data source.

Type declaration

NameTypeDescription
bodystringThe text of the page.
formatPageFormatThe file format of the page. This format determines how the page should be chunked and vector-embedded.
metadata?PageMetadataArbitrary metadata for page.
sourceNamestringData source name.
title?stringA human-readable title.
urlstring-

Defined in

packages/mongodb-rag-core/src/Page.ts:6


PageAction

Ƭ PageAction: "created" | "updated" | "deleted"

Defined in

packages/mongodb-rag-core/src/Page.ts:44


PageFormat

Ƭ PageFormat: typeof pageFormats[number]

A canonical page format.

Defined in

packages/mongodb-rag-core/src/PageFormat.ts:78


PageMetadata

Ƭ PageMetadata: Object

Index signature

▪ [k: string]: unknown

Type declaration

NameTypeDescription
tags?string[]Arbitrary tags.

Defined in

packages/mongodb-rag-core/src/Page.ts:36


PageStore

Ƭ PageStore: Object

Data store for Page objects.

Type declaration

NameTypeDescription
close?() => Promise<void>Close connection to data store.
queryType?"mongodb" | stringThe format that the store uses for custom queries. If not specified, the store does not allow custom queries.
loadPages(args?: LoadPagesArgs<unknown>) => Promise<PersistedPage[]>Loads pages from the Page store.
updatePages(pages: PersistedPage[]) => Promise<void>Updates or adds the given pages in the store.

Defined in

packages/mongodb-rag-core/src/Page.ts:89


PersistedPage

Ƭ PersistedPage: Page & { action: PageAction ; updated: Date }

Represents a Page stored in the database.

Defined in

packages/mongodb-rag-core/src/Page.ts:49


Question

Ƭ Question: z.infer<typeof Question>

Defined in

packages/mongodb-rag-core/src/VerifiedAnswer.ts:5

packages/mongodb-rag-core/src/VerifiedAnswer.ts:12


Reference

Ƭ Reference: z.infer<typeof Reference>

A formatted reference for an assistant message.

For example, a Reference might be a docs page, dev center article, or a MongoDB University module.

Defined in

packages/mongodb-rag-core/src/services/conversations.ts:9

packages/mongodb-rag-core/src/services/conversations.ts:10


References

Ƭ References: z.infer<typeof References>

Defined in

packages/mongodb-rag-core/src/services/conversations.ts:15

packages/mongodb-rag-core/src/services/conversations.ts:16


VectorStore

Ƭ VectorStore<T>: Object

Generic vector store for vector-searchable data.

Type parameters

Name
T

Type declaration

NameType
close?() => Promise<void>
findNearestNeighbors(vector: number[], options?: Partial<FindNearestNeighborsOptions>) => Promise<WithScore<T>[]>

Defined in

packages/mongodb-rag-core/src/VectorStore.ts:4


VerifiedAnswer

Ƭ VerifiedAnswer: z.infer<typeof VerifiedAnswer>

Defined in

packages/mongodb-rag-core/src/VerifiedAnswer.ts:14

packages/mongodb-rag-core/src/VerifiedAnswer.ts:25


VerifiedAnswerStore

Ƭ VerifiedAnswerStore: VectorStore<VerifiedAnswer>

Defined in

packages/mongodb-rag-core/src/VerifiedAnswer.ts:26


WithScore

Ƭ WithScore<T>: T & { score: number }

Type parameters

Name
T

Defined in

packages/mongodb-rag-core/src/VectorStore.ts:16

Variables

CORE_ENV_VARS

Const CORE_ENV_VARS: Object

Type declaration

NameType
MONGODB_CONNECTION_URIstring
MONGODB_DATABASE_NAMEstring
NODE_ENVstring
OPENAI_API_KEYstring
OPENAI_CHAT_COMPLETION_DEPLOYMENTstring
OPENAI_CHAT_COMPLETION_MODEL_VERSIONstring
OPENAI_EMBEDDING_DEPLOYMENTstring
OPENAI_EMBEDDING_MODELstring
OPENAI_EMBEDDING_MODEL_VERSIONstring
OPENAI_ENDPOINTstring
VECTOR_SEARCH_INDEX_NAMEstring

Defined in

packages/mongodb-rag-core/src/CoreEnvVars.ts:1


Question

Const Question: ZodObject<{ embedding: ZodArray<ZodNumber, "many"> ; embedding_model: ZodString ; embedding_model_version: ZodString ; text: ZodString }, "strip", ZodTypeAny, { embedding: number[] ; embedding_model: string ; embedding_model_version: string ; text: string }, { embedding: number[] ; embedding_model: string ; embedding_model_version: string ; text: string }>

Defined in

packages/mongodb-rag-core/src/VerifiedAnswer.ts:5

packages/mongodb-rag-core/src/VerifiedAnswer.ts:12


Reference

Reference: ZodObject<{ title: ZodString ; url: ZodString }, "strip", ZodTypeAny, { title: string ; url: string }, { title: string ; url: string }>

Defined in

packages/mongodb-rag-core/src/services/conversations.ts:9

packages/mongodb-rag-core/src/services/conversations.ts:10


References

References: ZodArray<ZodObject<{ title: ZodString ; url: ZodString }, "strip", ZodTypeAny, { title: string ; url: string }, { title: string ; url: string }>, "many">

Defined in

packages/mongodb-rag-core/src/services/conversations.ts:15

packages/mongodb-rag-core/src/services/conversations.ts:16


VerifiedAnswer

Const VerifiedAnswer: ZodObject<{ _id: ZodString ; answer: ZodString ; author_email: ZodString ; created: ZodDate ; hidden: ZodOptional<ZodBoolean> ; question: ZodObject<{ embedding: ZodArray<ZodNumber, "many"> ; embedding_model: ZodString ; embedding_model_version: ZodString ; text: ZodString }, "strip", ZodTypeAny, { embedding: number[] ; embedding_model: string ; embedding_model_version: string ; text: string }, { embedding: number[] ; embedding_model: string ; embedding_model_version: string ; text: string }> = Question; references: ZodArray<ZodObject<{ title: ZodString ; url: ZodString }, "strip", ZodTypeAny, { title: string ; url: string }, { title: string ; url: string }>, "many"> ; updated: ZodOptional<ZodDate> }, "strip", ZodTypeAny, { _id: string ; answer: string ; author_email: string ; created: Date ; hidden?: boolean ; question: { text: string; embedding: number[]; embedding_model: string; embedding_model_version: string; } = Question; references: { url: string; title: string; }[] ; updated?: Date }, { _id: string ; answer: string ; author_email: string ; created: Date ; hidden?: boolean ; question: { text: string; embedding: number[]; embedding_model: string; embedding_model_version: string; } = Question; references: { url: string; title: string; }[] ; updated?: Date }>

Defined in

packages/mongodb-rag-core/src/VerifiedAnswer.ts:14

packages/mongodb-rag-core/src/VerifiedAnswer.ts:25


logger

Const logger: Logger

Defined in

packages/mongodb-rag-core/src/services/logger.ts:42


pageFormats

Const pageFormats: ("txt" | "md" | "mdx" | "restructuredtext" | "csv" | "json" | "yaml" | "toml" | "xml" | "openapi-yaml" | "openapi-json" | "graphql" | "c" | "cpp" | "csharp" | "go" | "html" | "java" | "javascript" | "kotlin" | "latex" | "objective-c" | "php" | "python" | "ruby" | "rust" | "scala" | "shell" | "swift" | "typescript")[]

The list of canonical file formats that we support for pages.

Defined in

packages/mongodb-rag-core/src/PageFormat.ts:49

Functions

asPageFormat

asPageFormat(str): undefined | "txt" | "md" | "mdx" | "restructuredtext" | "csv" | "json" | "yaml" | "toml" | "xml" | "openapi-yaml" | "openapi-json" | "graphql" | "c" | "cpp" | "csharp" | "go" | "html" | "java" | "javascript" | "kotlin" | "latex" | "objective-c" | "php" | "python" | "ruby" | "rust" | "scala" | "shell" | "swift" | "typescript"

Maps a string to the canonical page format it represents.

Parameters

NameType
strstring

Returns

undefined | "txt" | "md" | "mdx" | "restructuredtext" | "csv" | "json" | "yaml" | "toml" | "xml" | "openapi-yaml" | "openapi-json" | "graphql" | "c" | "cpp" | "csharp" | "go" | "html" | "java" | "javascript" | "kotlin" | "latex" | "objective-c" | "php" | "python" | "ruby" | "rust" | "scala" | "shell" | "swift" | "typescript"

The canonical page format, or undefined if the string is not a recognized page format.

Defined in

packages/mongodb-rag-core/src/PageFormat.ts:67


assertEnvVars

assertEnvVars<T>(ENV_VARS): T

Type parameters

NameType
Textends Record<string, string>

Parameters

NameType
ENV_VARST

Returns

T

Defined in

packages/mongodb-rag-core/src/assertEnvVars.ts:1


createLoggerMessage

createLoggerMessage(«destructured»): Object

Parameters

NameType
«destructured»CreateMessageParams

Returns

Object

NameType
ipAddressundefined | string
messagestring
requestBodyunknown
requestIdundefined | string

Defined in

packages/mongodb-rag-core/src/services/logger.ts:10


extractFrontMatter

extractFrontMatter<T>(text, language?, delimiter?): Object

This function extracts frontmatter from a string. The generic type does not validate that the frontmatter conforms to the type. It just provides the type for developer convenience.

Type parameters

NameType
Textends Record<string, unknown>

Parameters

NameType
textstring
language?string
delimiter?string

Returns

Object

NameType
bodystring
metadata?T

Defined in

packages/mongodb-rag-core/src/extractFrontMatter.ts:10


filterDefined

filterDefined<T>(array): Exclude<T, undefined>[]

Given an array of possibly undefined T, return those that are defined.

Type parameters

Name
T

Parameters

NameType
arrayT[]

Returns

Exclude<T, undefined>[]

Defined in

packages/mongodb-rag-core/src/arrayFilters.ts:14


filterFulfilled

filterFulfilled<T>(array): PromiseFulfilledResult<T>[]

Given an array of PromiseSettledResults, return those that are fulfilled as PromiseFulfilledResults.

Type parameters

Name
T

Parameters

NameType
arrayPromiseSettledResult<T>[]

Returns

PromiseFulfilledResult<T>[]

Defined in

packages/mongodb-rag-core/src/arrayFilters.ts:4


isPageFormat

isPageFormat(str): str is "txt" | "md" | "mdx" | "restructuredtext" | "csv" | "json" | "yaml" | "toml" | "xml" | "openapi-yaml" | "openapi-json" | "graphql" | "c" | "cpp" | "csharp" | "go" | "html" | "java" | "javascript" | "kotlin" | "latex" | "objective-c" | "php" | "python" | "ruby" | "rust" | "scala" | "shell" | "swift" | "typescript"

Type guard to check if a string is a canonical page format.

Parameters

NameType
strstring

Returns

str is "txt" | "md" | "mdx" | "restructuredtext" | "csv" | "json" | "yaml" | "toml" | "xml" | "openapi-yaml" | "openapi-json" | "graphql" | "c" | "cpp" | "csharp" | "go" | "html" | "java" | "javascript" | "kotlin" | "latex" | "objective-c" | "php" | "python" | "ruby" | "rust" | "scala" | "shell" | "swift" | "typescript"

Defined in

packages/mongodb-rag-core/src/PageFormat.ts:83


makeLangChainEmbedder

makeLangChainEmbedder(«destructured»): Embedder

Constructor for implementation of the Embedder using a LangChain.js Embeddings class.

Parameters

NameType
«destructured»MakeLangChainEmbedderParams

Returns

Embedder

Defined in

packages/mongodb-rag-core/src/LangChainEmbedder.ts:14


makeMongoDbEmbeddedContentStore

makeMongoDbEmbeddedContentStore(«destructured»): EmbeddedContentStore & DatabaseConnection

Parameters

NameType
«destructured»MakeMongoDbDatabaseConnectionParams

Returns

EmbeddedContentStore & DatabaseConnection

Defined in

packages/mongodb-rag-core/src/MongoDbEmbeddedContentStore.ts:11


makeMongoDbPageStore

makeMongoDbPageStore(«destructured»): MongoDbPageStore

Data store for Page objects using MongoDB.

Parameters

NameType
«destructured»MakeMongoDbDatabaseConnectionParams

Returns

MongoDbPageStore

Defined in

packages/mongodb-rag-core/src/MongoDbPageStore.ts:22


makeMongoDbVerifiedAnswerStore

makeMongoDbVerifiedAnswerStore(«destructured»): VerifiedAnswerStore & DatabaseConnection

Parameters

NameType
«destructured»MakeMongoDbDatabaseConnectionParams & { collectionName: string }

Returns

VerifiedAnswerStore & DatabaseConnection

Defined in

packages/mongodb-rag-core/src/MongoDbVerifiedAnswerStore.ts:9


makeOpenAiEmbedder

makeOpenAiEmbedder(«destructured»): Embedder

Constructor for implementation of the Embedder using OpenAI Embeddings API.

Parameters

NameType
«destructured»MakeOpenAiEmbedderArgs

Returns

Embedder

Defined in

packages/mongodb-rag-core/src/OpenAiEmbedder.ts:28


makeTypeChatJsonTranslateFunc

makeTypeChatJsonTranslateFunc<SchemaType>(«destructured»): (prompt: string) => Promise<SchemaType>

Type parameters

NameType
SchemaTypeextends object

Parameters

NameType
«destructured»MakeTypeChatJsonTranslateFuncArgs

Returns

fn

▸ (prompt): Promise<SchemaType>

Parameters
NameType
promptstring
Returns

Promise<SchemaType>

Defined in

packages/mongodb-rag-core/src/TypeChatJsonTranslateFunc.ts:38


pageFormat

pageFormat(str, defaultPageFormat?): PageFormat

Converts a string to a canonical page format. If the string is not a recognized page format or a synonym for one, this returns a default page format.

Parameters

NameTypeDefault value
strstringundefined
defaultPageFormat"txt" | "md" | "mdx" | "restructuredtext" | "csv" | "json" | "yaml" | "toml" | "xml" | "openapi-yaml" | "openapi-json" | "graphql" | "c" | "cpp" | "csharp" | "go" | "html" | "java" | "javascript" | "kotlin" | "latex" | "objective-c" | "php" | "python" | "ruby" | "rust" | "scala" | "shell" | "swift" | "typescript""txt"

Returns

PageFormat

Defined in

packages/mongodb-rag-core/src/PageFormat.ts:92


removeFrontMatter

removeFrontMatter(content, options?): string

Parameters

NameType
contentstring
options?FrontMatterOptions

Returns

string

Defined in

packages/mongodb-rag-core/src/removeFrontMatter.ts:2


updateFrontMatter

updateFrontMatter(text, metadataIn): string

Parameters

NameType
textstring
metadataInRecord<string, unknown>

Returns

string

Defined in

packages/mongodb-rag-core/src/updateFrontMatter.ts:4