-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e3f4545
commit 12d4172
Showing
6 changed files
with
64 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from fastapi import APIRouter, Security | ||
|
||
from app.helpers import VectorStore | ||
from app.schemas.chunks import Chunks | ||
from app.schemas.search import SearchRequest | ||
from app.utils.lifespan import clients | ||
from app.utils.security import check_api_key | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.post("/search") | ||
async def search(request: SearchRequest, user: str = Security(check_api_key)) -> Chunks: | ||
""" | ||
Similarity search for chunks in the vector store. | ||
Parameters: | ||
request (SearchRequest): The search request. | ||
user (str): The user. | ||
Returns: | ||
Chunks: The chunks. | ||
""" | ||
|
||
vectorstore = VectorStore(clients=clients, user=user) | ||
data = vectorstore.search(prompt=request.prompt, collection_names=request.collections, k=request.k, score_threshold=request.score_threshold) | ||
|
||
return Chunks(data=data) |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from typing import List, Optional | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class SearchRequest(BaseModel): | ||
prompt: str | ||
collections: List[str] | ||
k: int | ||
score_threshold: Optional[float] = None |
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