# JavaScript SDK

Mindplug is the easiest solution to creating and managing embeddings. Add long term memory to your LLMs, perform semantic data analysis and easily filter data based on metadata. Connect your app to external web sources using our smart endpoint.

### <mark style="color:purple;">Install Mindplug</mark>

NPM:

```
npm install mindplug
```

yarn:

```
yarn add mindplug
```

### <mark style="color:purple;">Initialize Mindplug</mark>

Obtain an API key from [Mindplug](https://mindplug.io/) dashboard.

```
import Mindplug from 'mindplug';
const mindplug = new Mindplug({mindplugKey: <SAMPLE KEY>});
```

If you don't yet have access, please [book an onboarding call](https://calendly.com/cheraamritpal/30min).

### <mark style="color:purple;">Store Data</mark>

**All storage of data requires a db and a collection.**

Store text. Requires content

```
mindplug.store({
  db: "first database",
  collection: "any collection",
  content: "hello, sample text to store",
});
```

Store PDF file. Requires an object of type File under 50MB

```
mindplug.storePDF({
  db: "first database",
  collection: "any collection",
  file: <SAMPLE FILE>
});
```

Store webpage. Requires the webpage url

```
mindplug.storeWeb({
  db: "first database",
  collection: "any collection",
  url: "https://mindplug.io"
});
```

Store audio. Requires a MP3 or WAV file under 20MB

```
// must pass an openaiKey to constructor
mindplug.storeAudio({
  db: "first database",
  collection: "any collection",
  file: <SAMPLE FILE> 
});
```

**Storing - Advanced Techniques**

A `metadata` of type JSON and a `chunkSize` of type number may also be passed to each storage function. Metadata is used to easily filter for data. Chunk size is used to split large data into smaller batches. By default the data is split in about 1024 character chunks.

```
mindplug.store({
  db: "first database",
  collection: "any collection",
  content: "hello, sample text to store",
  metadata: {
    purpose: "to learn"
  },
  chunkSize: 512
});
```

###

### <mark style="color:purple;">Query Data</mark>

Semantic search. Search stored data by meaning of text.

```
mindplug.query({
  db: "first database",
  collection: "any collection",
  search: "What fruit is in the fridge?"
});
```

Query by vector ids.

```
mindplug.queryByIds({
  db: "first database",
  collection: "any collection",
  vectorIds: ["ID-1", "ID-2"]
});
```

Query by collection. Returns the recent 10 vectors from the collection.

```
mindplug.queryByCollection({
  db: "first database",
  collection: "any collection"
});
```

**Query - Advanced Techniques**

By default, mindplug returns the 3 best matches for the searched data. You can change this by passing a `count` parameter. You can also filter the stored data based on metadata by passing in a `metadataFilters` parameter.

```
mindplug.query({
  db: "first database",
  collection: "any collection",
  search: "What are the benefits of Solana blockchain?",
  metadataFilters: {
    genre: ["technology", "blockchain"]
  },
  count: 1
});
```

For more information on using metadataFilters, please see our API [documentation](https://docs.mindplug.io/api/query/using-metadata-filters)

####

### <mark style="color:purple;">Delete data</mark>

Delete by vector ids.

```
mindplug.deleteByIds({
  db: "first database",
  collection: "any collection",
  vectorIds: ["ID-1", "ID-2"]
});
```

Delete by upload id. Upload id is returned every time new data is stored

```
mindplug.deleteByUploadId({
  db: "first database",
  collection: "any collection",
  uploadId: "UPLOAD-ID"
});
```

Delete collection. Also deletes all vectors stored within.

```
mindplug.deleteCollection({
  db: "first database",
  collection: "any collection"
});
```

Delete project. Also deletes all collections and vectors stored within.

```
mindplug.deleteProject({
  db: "first database"
});
```

####

### <mark style="color:purple;">List data</mark>

List Collections.

```
mindplug.listCollections({
  db: "first database"
});
```

List projects.

```
mindplug.listProjects();
```

### <mark style="color:purple;">Smart Google Search</mark>

Google search from select sources.

```
mindplug.searchWeb({
  search: "How to cook pasta?"
});
```

You can easily manage all your data in the Mindplug dashboard.

### <mark style="color:purple;">Smart - Parsing Webpage</mark>

Get all text from a webpage given its URL.

```
mindplug.parseWebpage({
  url: "https://mindplug.io"
});
```

Returns all text on the webpage.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mindplug.io/javascript-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
