Skip to content
This repository was archived by the owner on Mar 28, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "getindexify",
"version": "0.0.19",
"version": "0.0.20",
"description": "This is the TypeScript client for interacting with the Indexify service.",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
4 changes: 3 additions & 1 deletion packages/langchain/tests/langchain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ jest.setTimeout(30000);

test("Langchain Rag", async () => {
// setup client
const client = await IndexifyClient.createNamespace("testlangchain");
const client = await IndexifyClient.createNamespace({
namespace: "testlangchain",
});
client.addExtractionPolicy({
extractor: "tensorlake/minilm-l6",
name: "minilml6",
Expand Down
24 changes: 16 additions & 8 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,24 @@ class IndexifyClient {
return this.request("GET", endpoint);
}

static async namespaces(): Promise<INamespace[]> {
const response = await axios.get(`${DEFAULT_SERVICE_URL}/namespaces`);
static async namespaces({
serviceUrl = DEFAULT_SERVICE_URL,
}: {
serviceUrl?: string;
} = {}): Promise<INamespace[]> {
const response = await axios.get(`${serviceUrl}/namespaces`);
return response.data.namespaces;
}

static async createNamespace(
namespace: string,
extraction_policies?: IExtractionPolicy[],
labels?: Record<string, string>
) {
static async createNamespace({
namespace,
extraction_policies,
labels,
}: {
namespace: string;
extraction_policies?: IExtractionPolicy[];
labels?: Record<string, string>;
}) {
await axios.post(`${DEFAULT_SERVICE_URL}/namespaces`, {
name: namespace,
extraction_policies: extraction_policies ?? [],
Expand All @@ -126,7 +134,7 @@ class IndexifyClient {
}

async extractors(): Promise<Extractor[]> {
const response = await axios.get(`${DEFAULT_SERVICE_URL}/extractors`);
const response = await axios.get(`${this.serviceUrl}/extractors`);
const extractorsData = response.data.extractors as IExtractor[];
return extractorsData.map((data) => new Extractor(data));
}
Expand Down
46 changes: 29 additions & 17 deletions tests/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ test("Create Client", async () => {
});

test("Create Namespace", async () => {
const client = await IndexifyClient.createNamespace("testnamespace", [
{
extractor: "tensorlake/minilm-l6",
name: "testpolicy",
},
]);
const client = await IndexifyClient.createNamespace({
namespace: "testnamespace",
extraction_policies: [
{
extractor: "tensorlake/minilm-l6",
name: "testpolicy",
},
],
});

expect(client.namespace).toBe("testnamespace");
// test get namespaces
Expand All @@ -31,11 +34,9 @@ test("Get Extractors", async () => {
});

test("Add Documents", async () => {
const client = await IndexifyClient.createNamespace(
"test.adddocuments",
[],
{}
);
const client = await IndexifyClient.createNamespace({
namespace: "test.adddocuments",
});

// add single documents
await client.addDocuments({ text: "This is a test", labels: {} });
Expand Down Expand Up @@ -74,7 +75,10 @@ test("Search", async () => {
labels_eq: "source:test",
};

const client = await IndexifyClient.createNamespace("testsearch");
const client = await IndexifyClient.createNamespace({
namespace: "testsearch",
});
console.log('got namespace?', client.namespace)
const resp = await client.addExtractionPolicy(policy);
expect(resp.index_names.length).toBe(1);

Expand All @@ -85,7 +89,7 @@ test("Search", async () => {
{ text: "This is a test2", labels: { source: "test" } },
]);

await new Promise((r) => setTimeout(r, 10000));
await new Promise((r) => setTimeout(r, 15000));

const searchResult = await client.searchIndex(indexName, "test", 3);
expect(searchResult.length).toBe(2);
Expand All @@ -99,14 +103,18 @@ test("Upload file", async () => {
input_params: {},
};

const client = await IndexifyClient.createNamespace("testuploadfile");
const client = await IndexifyClient.createNamespace({
namespace: "testuploadfile",
});
client.addExtractionPolicy(policy);
await client.uploadFile(`${__dirname}/files/test.txt`);
console.log("done");
});

test("Get content", async () => {
const client = await IndexifyClient.createNamespace("testgetcontent");
const client = await IndexifyClient.createNamespace({
namespace: "testgetcontent",
});
await client.addDocuments([
{ text: "This is a test1", labels: { source: "test" } },
{ text: "This is a test2", labels: { source: "test" } },
Expand All @@ -126,7 +134,9 @@ test("Get content", async () => {
});

test("Download content", async () => {
const client = await IndexifyClient.createNamespace("testgetcontent");
const client = await IndexifyClient.createNamespace({
namespace: "testgetcontent",
});
await client.addDocuments([
{ text: "This is a download", labels: { source: "testdownload" } },
]);
Expand All @@ -139,7 +149,9 @@ test("Download content", async () => {
});

test("Get Extraction Policies", async () => {
const client = await IndexifyClient.createNamespace("testgetpolicies");
const client = await IndexifyClient.createNamespace({
namespace: "testgetpolicies",
});

await client.addExtractionPolicy({
extractor: "tensorlake/minilm-l6",
Expand Down