Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: get documents API and text files connector #31

Merged
merged 1 commit into from
Mar 14, 2024
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
5 changes: 3 additions & 2 deletions selfie/api/documents.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
from typing import List, Optional

from fastapi import APIRouter, Query
Expand Down Expand Up @@ -27,8 +28,8 @@ class FetchedDocument(BaseModel):
id: int = Field(..., description="The unique identifier of the document")
name: str = Field(..., description="The name of the document")
size: int = Field(..., description="The size of the document")
created_at: str = Field(..., description="The timestamp of the document creation")
updated_at: str = Field(..., description="The timestamp of the document update")
created_at: datetime = Field(..., description="The timestamp of the document creation")
updated_at: datetime = Field(..., description="The timestamp of the document update")
content_type: str = Field(..., description="The content type of the document")
connector_name: str = Field(..., description="The name of the connector")

Expand Down
5 changes: 1 addition & 4 deletions selfie/connectors/text_files/uischema.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"files": {
"ui:widget": "nativeFile",
"ui:options": {
"accept": ".json"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to restrict to .txt files?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a bit too restrictive. JSON files, markdown files, etc, should all work just fine with this connector, so in this case I think it's better to leave in the hands of the user.

}
"ui:widget": "nativeFile"
}
}
4 changes: 3 additions & 1 deletion selfie/embeddings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def __init__(self, character_name, storage_path: str = config.embeddings_storage
self.completion = completion or get_default_completion()
self.character_name = character_name
self.embeddings = Embeddings(
hybrid=True,
sqlite={"wal": True},
# For now, sqlite w/the default driver is the only way to use WAL.
content=True
Expand Down Expand Up @@ -346,6 +347,7 @@ async def recall(
include_summary=True,
local_llm=True,
min_score=0.4,
hybrid_search_weight=1.0, # TODO: Setting this to only use the dense index until this is tuned, e.g., with min_score
):
if min_score is None:
min_score = 0.4
Expand All @@ -354,7 +356,7 @@ async def recall(
return {"documents": [], "summary": "No documents found.", "mean_score": 0}
self.embeddings.load(self.storage_path)

results = self._query(where="similar(:topic)", parameters={"topic": topic}, limit=limit)
results = self._query(where=f"similar(:topic, {hybrid_search_weight})", parameters={"topic": topic}, limit=limit)
documents_list: List[ScoredEmbeddingDocumentModel] = []
for result in results:
document = EmbeddingDocumentModel(
Expand Down