Redactive Node SDK
The Redactive Node SDK provides a robust and intuitive interface for interacting with the Redactive platform, enabling developers to seamlessly integrate powerful data redaction and anonymization capabilities into their Node applications.
Installation
In order to use the package to integrate with Redactive.ai, run:
npm install redactive
There is no need to clone this repository.
If you would like to modify this package, clone the repo and install from source:
npm install ./sdks/node
Requirements
Usage
The library has following components.
- AuthClient - provides functionality to interact with data sources
- SearchClient - provides functionality to search chunks with Redactive search service in gRPC
- MultiUserClient - provides functionality manage multi-user search with Redactive search service
AuthClient
AuthClient needs to be configured with your account's API key which is
available in the Apps page at Redactive Dashboard.
import { AuthClient } from "@redactive/redactive";
const redirectUri = "https://url-debugger.vercel.app";
const provider = "confluence";
const signInUrl = await client.beginConnection({ provider, redirectUri });
const response = await client.exchangeTokens("OAUTH2-AUTH-CODE");
SearchClient
With the Redactive access_token, you can perform three types of searches using the Redactive Search service:
- Semantic Query Search: Retrieve relevant chunks of information that are semantically related to a user query.
- URL-based Search: Obtain all the chunks from a document by specifying its URL.
- Document Name Search: Query for all the chunks from a document based on the name of the document.
import { SearchClient } from "@redactive/redactive";
const client = new SearchClient();
const accessToken = "REDACTIVE-ACCESS-TOKEN";
const semanticQuery = "Tell me about AI";
await client.queryChunks({ accessToken, semanticQuery });
const url = "https://example.com/document";
await client.getChunksByUrl({ accessToken, url });
const documentName = "AI Research Paper";
await client.queryChunksByDocumentName({ accessToken, documentName });
Filters
Query methods, i.e. queryChunks
, queryChunksByDocumentName
, support a set of optional filters. The filters are applied in a logical 'AND' operation. If a data source provider does not support a filter-type, then no results from that provider are returned.
import { Filters } from "@redactive/redactive/grpc/search";
const lastWeek = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000);
const filters: Filters = {
scope: ["confluence"],
created: {
before: lastWeek
},
modified: {
after: lastWeek
},
userEmails: ["myEmail@example.com"],
includeContentInTrash: true
};
await client.queryChunks({ accessToken, semanticQuery, filters });
Multi-User Client
The MultiUserClient
class helps manage multiple users' authentication and access to the Redactive search service.
import { MultiUserClient } from "@redactive/redactive";
const multiUserClient = MultiUserClient(
"REDACTIVE-API-KEY",
"https://example.com/callback/",
readUserData,
multiUserClient
);
const userId = "myUserId";
const connectionUrl = await multiUserClient.getBeginConnectionUrl(userId, "confluence");
let [signInCode, state] = ["", ""];
const isConnectionSuccessful = await multiUserClient.handleConnectionCallback(userId, signInCode, state);
const semanticQuery = "Tell me about the missing research vessel, the Borealis";
const chunks = await multiUserClient.queryChunks({ userId, semanticQuery });
Development
The Node SDK code can be found thesdks/node
directory in Redactive Github Repository.
In order to comply with the repository style guide, we recommend running the following tools.
To format your code, run:
pnpm format:fix
To lint your code, run:
pnpm lint:fix
To test changes, run:
pnpm test
To build Python SDK, run:
pnpm build
To install local version, run:
npm install ./sdks/node
Contribution Guide
Please check here