-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add & update docstrings, type hints, param defaults (#47)
* Add, update docstrings, type hints, param defaults * Update SDK readme's for multi-user clients * Add doc example for filters
- Loading branch information
Showing
11 changed files
with
362 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ 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 | ||
|
||
|
@@ -76,6 +77,57 @@ 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. | ||
|
||
```typescript | ||
import { Filters } from "@redactive/redactive/grpc/search"; | ||
|
||
// Query chunks from Confluence only, that are from documents created before last week, modified since last week, | ||
// and that are from documents associated with a user's email. Include chunks from trashed documents. | ||
const lastWeek = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000); | ||
const filters: Filters = { | ||
scope: ["confluence"], | ||
created: { | ||
before: lastWeek | ||
}, | ||
modified: { | ||
after: lastWeek | ||
}, | ||
userEmails: ["[email protected]"], | ||
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. | ||
|
||
```typescript | ||
import { MultiUserClient } from "@redactive/redactive"; | ||
|
||
const multiUserClient = MultiUserClient( | ||
"REDACTIVE-API-KEY", | ||
"https://example.com/callback/", | ||
readUserData, | ||
multiUserClient | ||
); | ||
|
||
// Present `connection_url` in browser for user to interact with: | ||
const userId = "myUserId"; | ||
const connectionUrl = await multiUserClient.getBeginConnectionUrl(userId, "confluence"); | ||
|
||
// On user return from OAuth connection flow: | ||
let [signInCode, state] = ["", ""]; // from URL query parameters | ||
const isConnectionSuccessful = await multiUserClient.handleConnectionCallback(userId, signInCode, state); | ||
|
||
// User can now use Redactive search service via `MultiUserClient`'s other methods: | ||
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 the`sdks/node` directory in Redactive Github Repository. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,10 +24,11 @@ python -m pip install . | |
|
||
## Usage | ||
|
||
The library has following components. | ||
The library has the following components: | ||
|
||
- **AuthClient** - provides functionality to interact with data sources | ||
- **SearchClient** - provides functionality to search chunks with Redactive search service in gRPC | ||
- **SearchClient** - provides functionality to search chunks with Redactive search service | ||
- **MultiUserClient** - provides functionality manage multi-user search with Redactive search service | ||
- **RerankingSearchClient** [Experimental] - retrieves extra results, then re-ranks them using a more precise ranking function, returning the top_k results | ||
|
||
### AuthClient | ||
|
@@ -78,13 +79,76 @@ client.get_chunks_by_url( | |
url="https://example.com/document" | ||
) | ||
|
||
# Document Name Search : retrieve all chunks of a document identified by its name | ||
# Document Name Search: retrieve all chunks of a document identified by its name | ||
client.query_chunks_by_document_name( | ||
access_token="REDACTIVE-USER-ACCESS-TOKEN", | ||
document_name="Project Plan" | ||
) | ||
``` | ||
|
||
### Filters | ||
|
||
Query methods, i.e. `query_chunks`, `query_chunks_by_document_name`, 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. | ||
|
||
```python | ||
from datetime import datetime, timedelta | ||
from redactive.search_client import SearchClient | ||
from redactive.grpc.v1 import Filters | ||
|
||
client = SearchClient() | ||
|
||
# Query chunks from Confluence only, that are from documents created before last week, modified since last week, | ||
# and that are from documents associated with a user's email. Include chunks from trashed documents. | ||
last_week = datetime.now() - timedelta(weeks=1) | ||
filters = Filters().from_dict({ | ||
"scope": ["confluence"], | ||
"created": { | ||
"before": last_week, | ||
}, | ||
"modified": { | ||
"after": last_week, | ||
}, | ||
"userEmails": ["[email protected]"], | ||
"includeContentInTrash": True, | ||
}) | ||
client.query_chunks( | ||
access_token="REDACTIVE-USER-ACCESS-TOKEN", | ||
semantic_query="Tell me about AI", | ||
filters=filters | ||
) | ||
``` | ||
|
||
### Multi-User Client | ||
|
||
The `MultiUserClient` class helps manage multiple users' authentication and access to the Redactive search service. | ||
|
||
```python | ||
from redactive.multi_user_client import MultiUserClient | ||
|
||
multi_user_client = MultiUserClient( | ||
api_key="REDACTIVE-API-KEY", | ||
callback_uri="https://example.com/callback/", | ||
read_user_data=..., | ||
write_user_data=..., | ||
) | ||
|
||
# Present `connection_url` in browser for user to interact with: | ||
user_id = ... | ||
connection_url = await multi_user_client.get_begin_connection_url(user_id=user_id, provider="confluence") | ||
|
||
# On user return from OAuth connection flow: | ||
sign_in_code, state = ..., ... # from URL query parameters | ||
is_connection_successful = await multi_user_client.handle_connection_callback( | ||
user_id=user_id, | ||
sign_in_code=sign_in_code, | ||
state=state | ||
) | ||
|
||
# User can now use Redactive search service via `MultiUserClient`'s other methods: | ||
semantic_query = "Tell me about the missing research vessel, the Borealis" | ||
chunks = await multi_user_client.query_chunks(user_id=user_id, semantic_query=semantic_query) | ||
``` | ||
|
||
## Development | ||
|
||
The Python SDK code can be found the`sdks/python` directory in Redactive Github Repository. | ||
|
Oops, something went wrong.