Skip to content

Commit

Permalink
Feature/tweak downgrade logic (#1577)
Browse files Browse the repository at this point in the history
* tweak downgrade

* fix js sdk

* fix js sdk

* fix upgrade logic

* up
  • Loading branch information
emrgnt-cmplxty authored Nov 12, 2024
1 parent a7bed5c commit 116c7e0
Show file tree
Hide file tree
Showing 21 changed files with 351 additions and 396 deletions.
2 changes: 1 addition & 1 deletion js/sdk/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "r2r-js",
"version": "0.3.15",
"version": "0.3.16",
"description": "",
"main": "dist/index.js",
"browser": "dist/index.browser.js",
Expand Down
31 changes: 7 additions & 24 deletions js/sdk/src/r2rClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1921,41 +1921,24 @@ export class r2rClient {
/**
* Search over documents.
* @param query The query to search for.
* @param settings Settings for the document search.
* @param vector_search_settings Settings for the document search.
* @returns A promise that resolves to the response from the server.
*/
@feature("searchDocuments")
async searchDocuments(
query: string,
settings?: {
searchOverMetadata?: boolean;
metadataKeys?: string[];
searchOverBody?: boolean;
filters?: Record<string, any>;
searchFilters?: Record<string, any>;
offset?: number;
limit?: number;
titleWeight?: number;
metadataWeight?: number;
},
vector_search_settings?: VectorSearchSettings | Record<string, any>,
): Promise<any> {
this._ensureAuthenticated();

const json_data: Record<string, any> = {
query,
settings: {
search_over_metadata: settings?.searchOverMetadata ?? true,
metadata_keys: settings?.metadataKeys ?? ["title"],
search_over_body: settings?.searchOverBody ?? false,
filters: settings?.filters ?? {},
search_filters: settings?.searchFilters ?? {},
offset: settings?.offset ?? 0,
limit: settings?.limit ?? 10,
title_weight: settings?.titleWeight ?? 0.5,
metadata_weight: settings?.metadataWeight ?? 0.5,
},
vector_search_settings,
};

Object.keys(json_data).forEach(
(key) => json_data[key] === undefined && delete json_data[key],
);

return await this._makeRequest("POST", "search_documents", {
data: json_data,
});
Expand Down
2 changes: 1 addition & 1 deletion py/core/main/api/ingestion_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
Depends,
File,
Form,
HTTPException,
Path,
Query,
UploadFile,
HTTPException,
)
from pydantic import Json

Expand Down
4 changes: 2 additions & 2 deletions py/core/main/app.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from typing import Union

from core.base import R2RException
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
from fastapi.middleware.cors import CORSMiddleware
from fastapi.openapi.utils import get_openapi
from fastapi.responses import JSONResponse

from core.base import R2RException
from core.providers import (
HatchetOrchestrationProvider,
SimpleOrchestrationProvider,
Expand Down
5 changes: 3 additions & 2 deletions py/core/main/app_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
from typing import Optional

from apscheduler.schedulers.asyncio import AsyncIOScheduler
from core.base import R2RException
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse

from core.base import R2RException

from .assembly import R2RBuilder, R2RConfig

Expand Down
3 changes: 3 additions & 0 deletions py/core/main/services/ingestion_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ async def augment_document_info(

document_info.summary = response.choices[0].message.content # type: ignore

if not document_info.summary:
raise ValueError("Expected a generated response.")

embedding = await self.providers.embedding.async_get_embedding(
text=document_info.summary,
)
Expand Down
1 change: 1 addition & 0 deletions py/core/main/services/kg_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import time
from typing import AsyncGenerator, Optional
from uuid import UUID

from fastapi import HTTPException

from core.base import KGExtractionStatus, RunManager
Expand Down
1 change: 1 addition & 0 deletions py/core/pipes/kg/deduplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
from typing import Any, Union
from uuid import UUID

from fastapi import HTTPException

from core.base import AsyncState
Expand Down
1 change: 1 addition & 0 deletions py/core/pipes/kg/prompt_tuning.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
from typing import Any
from uuid import UUID

from fastapi import HTTPException

from core.base import (
Expand Down
3 changes: 1 addition & 2 deletions py/core/providers/auth/r2r_auth.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import logging
import os
from datetime import datetime, timedelta, timezone
from fastapi import HTTPException

import jwt
from fastapi import Depends
from fastapi import Depends, HTTPException
from fastapi.security import OAuth2PasswordBearer

from core.base import (
Expand Down
1 change: 1 addition & 0 deletions py/core/providers/database/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import datetime
from typing import Optional, Union
from uuid import UUID, uuid4

from fastapi import HTTPException

from core.base import (
Expand Down
6 changes: 6 additions & 0 deletions py/core/providers/database/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ async def upsert_documents_overview(
else:
wait_time = 0.1 * (2**retries) # Exponential backoff
await asyncio.sleep(wait_time)
except Exception as e:
if 'column "summary"' in str(e):
raise ValueError(
"Document schema is missing 'summary' and 'summary_embedding' columns. Call `r2r db upgrade` to carry out the necessary migration."
)
raise

async def delete_from_documents_overview(
self, document_id: UUID, version: Optional[str] = None
Expand Down
2 changes: 1 addition & 1 deletion py/core/providers/database/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import logging
from typing import BinaryIO, Optional, Union
from uuid import UUID
from fastapi import HTTPException

import asyncpg
from fastapi import HTTPException

from core.base import FileHandler, R2RException

Expand Down
2 changes: 1 addition & 1 deletion py/core/providers/database/kg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import time
from typing import Any, AsyncGenerator, Optional, Tuple
from uuid import UUID
from fastapi import HTTPException

import asyncpg
from asyncpg.exceptions import PostgresError, UndefinedTableError
from fastapi import HTTPException

from core.base import (
CommunityReport,
Expand Down
1 change: 1 addition & 0 deletions py/core/providers/database/user.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime
from typing import Optional, Union
from uuid import UUID

from fastapi import HTTPException

from core.base import CryptoProvider, UserHandler
Expand Down
Loading

0 comments on commit 116c7e0

Please sign in to comment.