Compare commits

...

2 Commits

Author SHA1 Message Date
Bert
2d49a26790 ensure table names are uri encoded for tables (#1189)
This prevents an issue where users can do something like:
```js
db.createTable('my-table#123123')
```
The server has logic to determine that '#' character is not allowed in
the table name, but currently this is being returned as 404 error
because it routes to `/v1/my-table#123123/create` and `#123123/create`
will not be parsed as part of path
2024-04-04 12:01:35 -07:00
qzhu
7f49f4cc35 add a default value for search.limit to be consistent with python sdk 2024-04-04 11:50:54 -07:00
2 changed files with 15 additions and 15 deletions

View File

@@ -38,7 +38,7 @@ export class Query<T = number[]> {
constructor (query?: T, tbl?: any, embeddings?: EmbeddingFunction<T>) { constructor (query?: T, tbl?: any, embeddings?: EmbeddingFunction<T>) {
this._tbl = tbl this._tbl = tbl
this._query = query this._query = query
this._limit = undefined this._limit = 10
this._nprobes = 20 this._nprobes = 20
this._refineFactor = undefined this._refineFactor = undefined
this._select = undefined this._select = undefined

View File

@@ -156,7 +156,7 @@ export class RemoteConnection implements Connection {
} }
const res = await this._client.post( const res = await this._client.post(
`/v1/table/${tableName}/create/`, `/v1/table/${encodeURIComponent(tableName)}/create/`,
buffer, buffer,
undefined, undefined,
'application/vnd.apache.arrow.stream' 'application/vnd.apache.arrow.stream'
@@ -177,7 +177,7 @@ export class RemoteConnection implements Connection {
} }
async dropTable (name: string): Promise<void> { async dropTable (name: string): Promise<void> {
await this._client.post(`/v1/table/${name}/drop/`) await this._client.post(`/v1/table/${encodeURIComponent(name)}/drop/`)
} }
withMiddleware (middleware: HttpMiddleware): Connection { withMiddleware (middleware: HttpMiddleware): Connection {
@@ -268,7 +268,7 @@ export class RemoteTable<T = number[]> implements Table<T> {
get schema (): Promise<any> { get schema (): Promise<any> {
return this._client return this._client
.post(`/v1/table/${this._name}/describe/`) .post(`/v1/table/${encodeURIComponent(this._name)}/describe/`)
.then(async (res) => { .then(async (res) => {
if (res.status !== 200) { if (res.status !== 200) {
throw new Error( throw new Error(
@@ -282,7 +282,7 @@ export class RemoteTable<T = number[]> implements Table<T> {
} }
search (query: T): Query<T> { search (query: T): Query<T> {
return new RemoteQuery(query, this._client, this._name) //, this._embeddings_new) return new RemoteQuery(query, this._client, encodeURIComponent(this._name)) //, this._embeddings_new)
} }
filter (where: string): Query<T> { filter (where: string): Query<T> {
@@ -324,7 +324,7 @@ export class RemoteTable<T = number[]> implements Table<T> {
const buffer = await fromTableToStreamBuffer(tbl, this._embeddings) const buffer = await fromTableToStreamBuffer(tbl, this._embeddings)
const res = await this._client.post( const res = await this._client.post(
`/v1/table/${this._name}/merge_insert/`, `/v1/table/${encodeURIComponent(this._name)}/merge_insert/`,
buffer, buffer,
queryParams, queryParams,
'application/vnd.apache.arrow.stream' 'application/vnd.apache.arrow.stream'
@@ -348,7 +348,7 @@ export class RemoteTable<T = number[]> implements Table<T> {
const buffer = await fromTableToStreamBuffer(tbl, this._embeddings) const buffer = await fromTableToStreamBuffer(tbl, this._embeddings)
const res = await this._client.post( const res = await this._client.post(
`/v1/table/${this._name}/insert/`, `/v1/table/${encodeURIComponent(this._name)}/insert/`,
buffer, buffer,
{ {
mode: 'append' mode: 'append'
@@ -374,7 +374,7 @@ export class RemoteTable<T = number[]> implements Table<T> {
} }
const buffer = await fromTableToStreamBuffer(tbl, this._embeddings) const buffer = await fromTableToStreamBuffer(tbl, this._embeddings)
const res = await this._client.post( const res = await this._client.post(
`/v1/table/${this._name}/insert/`, `/v1/table/${encodeURIComponent(this._name)}/insert/`,
buffer, buffer,
{ {
mode: 'overwrite' mode: 'overwrite'
@@ -421,7 +421,7 @@ export class RemoteTable<T = number[]> implements Table<T> {
index_cache_size: indexCacheSize index_cache_size: indexCacheSize
} }
const res = await this._client.post( const res = await this._client.post(
`/v1/table/${this._name}/create_index/`, `/v1/table/${encodeURIComponent(this._name)}/create_index/`,
data data
) )
if (res.status !== 200) { if (res.status !== 200) {
@@ -442,7 +442,7 @@ export class RemoteTable<T = number[]> implements Table<T> {
replace: true replace: true
} }
const res = await this._client.post( const res = await this._client.post(
`/v1/table/${this._name}/create_scalar_index/`, `/v1/table/${encodeURIComponent(this._name)}/create_scalar_index/`,
data data
) )
if (res.status !== 200) { if (res.status !== 200) {
@@ -455,14 +455,14 @@ export class RemoteTable<T = number[]> implements Table<T> {
} }
async countRows (filter?: string): Promise<number> { async countRows (filter?: string): Promise<number> {
const result = await this._client.post(`/v1/table/${this._name}/count_rows/`, { const result = await this._client.post(`/v1/table/${encodeURIComponent(this._name)}/count_rows/`, {
predicate: filter predicate: filter
}) })
return (await result.body()) return (await result.body())
} }
async delete (filter: string): Promise<void> { async delete (filter: string): Promise<void> {
await this._client.post(`/v1/table/${this._name}/delete/`, { await this._client.post(`/v1/table/${encodeURIComponent(this._name)}/delete/`, {
predicate: filter predicate: filter
}) })
} }
@@ -481,7 +481,7 @@ export class RemoteTable<T = number[]> implements Table<T> {
updates[key] = toSQL(value) updates[key] = toSQL(value)
} }
} }
await this._client.post(`/v1/table/${this._name}/update/`, { await this._client.post(`/v1/table/${encodeURIComponent(this._name)}/update/`, {
predicate: filter, predicate: filter,
updates: Object.entries(updates).map(([key, value]) => [key, value]) updates: Object.entries(updates).map(([key, value]) => [key, value])
}) })
@@ -489,7 +489,7 @@ export class RemoteTable<T = number[]> implements Table<T> {
async listIndices (): Promise<VectorIndex[]> { async listIndices (): Promise<VectorIndex[]> {
const results = await this._client.post( const results = await this._client.post(
`/v1/table/${this._name}/index/list/` `/v1/table/${encodeURIComponent(this._name)}/index/list/`
) )
return (await results.body()).indexes?.map((index: any) => ({ return (await results.body()).indexes?.map((index: any) => ({
columns: index.columns, columns: index.columns,
@@ -500,7 +500,7 @@ export class RemoteTable<T = number[]> implements Table<T> {
async indexStats (indexUuid: string): Promise<IndexStats> { async indexStats (indexUuid: string): Promise<IndexStats> {
const results = await this._client.post( const results = await this._client.post(
`/v1/table/${this._name}/index/${indexUuid}/stats/` `/v1/table/${encodeURIComponent(this._name)}/index/${indexUuid}/stats/`
) )
const body = await results.body() const body = await results.body()
return { return {