Basic Usage
npm
Constructor
Before starting, create a schema in Typesense with an id, a field for the vector and a field for the text. Add as many other fields as needed for the metadata.constructor(embeddings: Embeddings, config: TypesenseConfig): Constructs a new instance of theTypesenseclass.embeddings: An instance of theEmbeddingsclass used for embedding documents.config: Configuration object for the Typesense vector store.typesenseClient: Typesense client instance.schemaName: Name of the Typesense schema in which documents will be stored and searched.searchParams(optional): Typesense search parameters. Default is{ q: '*', per_page: 5, query_by: '' }.columnNames(optional): Column names configuration.vector(optional): Vector column name. Default is'vec'.pageContent(optional): Page content column name. Default is'text'.metadataColumnNames(optional): Metadata column names. Default is an empty array[].
import(optional): Replace the default import function for importing data to Typesense. This can affect the functionality of updating documents.
Methods
async addDocuments(documents: Document[]): Promise<void>: Adds documents to the vector store. The documents will be updated if there is a document with the same ID.static async fromDocuments(docs: Document[], embeddings: Embeddings, config: TypesenseConfig): Promise<Typesense>: Creates a Typesense vector store from a list of documents. Documents are added to the vector store during construction.static async fromTexts(texts: string[], metadatas: object[], embeddings: Embeddings, config: TypesenseConfig): Promise<Typesense>: Creates a Typesense vector store from a list of texts and associated metadata. Texts are converted to documents and added to the vector store during construction.async similaritySearch(query: string, k?: number, filter?: Record<string, unknown>): Promise<Document[]>: Searches for similar documents based on a query. Returns an array of similar documents.async deleteDocuments(documentIds: string[]): Promise<void>: Deletes documents from the vector store based on their IDs.
Related
- Vector store conceptual guide
- Vector store how-to guides
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.