Skip to content

Commit

Permalink
v2.3.16
Browse files Browse the repository at this point in the history
  • Loading branch information
ashpreetbedi committed Feb 4, 2024
1 parent 7e5da80 commit 0a8c767
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 19 deletions.
13 changes: 4 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,18 @@

Phidata is a toolkit for building autonomous AI applications using function calling.

Function calling is a powerful approach that lets LLMs take actions and dynamically choose their path based on the response,
just like how humans solve problems. For example:
- To build a RAG chatbot, instead of stuffing the prompt every time, give the assistant functions to search its knowledge base for relevant context, which results in better responses.
- To build text-to-SQL, give the assistant functions to view and describe tables, search its knowledge base for context and finally, inspect and run queries to get the answer.
- To build a customer support assistant, give the assistant functions to search the order history, product description or its knowledge base depending on the question.

Phidata provides `Assistants` that come with memory, knowledge, storage and tools, making it easy to build intelligent AI applications.
Function calling enables LLMs to achieve tasks by taking an action (function call) and intelligently choosing its next step based on the response,
just like how humans solve problems. Phidata provides `Assistants` with built-in memory, knowledge, storage and tools, making it easy to build intelligent AI applications.

![assistants-explanation](https://github.com/phidatahq/phidata/assets/22579644/7f420011-ab8c-410a-97cc-5ad2fc0fe9d8)

### Use phidata to build
## ⭐️ Use phidata to build

- **Knowledge Assistants:** Answer questions from documents (PDFs, text)
- **Research Assistants:** Perform research and summarize findings.
- **Data Assistants:** Analyze data by running SQL queries.
- **Python Assistants:** Perform tasks by running python code.
- **Customer Assistants:** Answer customer queries using product descriptions and purchase history.
- **Research Assistants:** Perform research and summarize findings.
- **Marketing Assistants:** Provide marketing insights, copywriting and content ideas.
- **Travel Assistants:** Help plan travel by researching destinations, flight and hotel prices.
- **Meal Prep Assistants:** Help plan meals by researching recipes and adding ingredients to shopping lists.
Expand Down
25 changes: 18 additions & 7 deletions phi/knowledge/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,18 @@ def document_lists(self) -> Iterator[List[Document]]:

def search(self, query: str, num_documents: Optional[int] = None) -> List[Document]:
"""Returns relevant documents matching the query"""

if self.vector_db is None:
logger.warning("No vector db provided")
try:
if self.vector_db is None:
logger.warning("No vector db provided")
return []

_num_documents = num_documents or self.num_documents
logger.debug(f"Getting {_num_documents} relevant documents for query: {query}")
return self.vector_db.search(query=query, limit=_num_documents)
except Exception as e:
logger.error(f"Error searching for documents: {e}")
return []

_num_documents = num_documents or self.num_documents
logger.debug(f"Getting {_num_documents} relevant documents for query: {query}")
return self.vector_db.search(query=query, limit=_num_documents)

def load(self, recreate: bool = False) -> None:
"""Load the knowledge base to the vector db"""

Expand Down Expand Up @@ -219,3 +222,11 @@ def exists(self) -> bool:
logger.warning("No vector db provided")
return False
return self.vector_db.exists()

def clear(self) -> bool:
"""Clear the knowledge base"""
if self.vector_db is None:
logger.warning("No vector db available")
return True

return self.vector_db.clear()
4 changes: 4 additions & 0 deletions phi/vectordb/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ def exists(self) -> bool:
@abstractmethod
def optimize(self) -> None:
raise NotImplementedError

@abstractmethod
def clear(self) -> bool:
raise NotImplementedError
10 changes: 9 additions & 1 deletion phi/vectordb/pgvector/pgvector.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,5 +322,13 @@ def optimize(self) -> None:
f"WITH (m = {self.index.m}, ef_construction = {self.index.ef_construction});"
)
)

logger.debug("==== Optimized Vector DB ====")

def clear(self) -> bool:
from sqlalchemy import delete

with self.Session() as sess:
with sess.begin():
stmt = delete(self.table)
sess.execute(stmt)
return True
10 changes: 9 additions & 1 deletion phi/vectordb/pgvector/pgvector2.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,5 +367,13 @@ def optimize(self) -> None:
f"WITH (m = {self.index.m}, ef_construction = {self.index.ef_construction});"
)
)

logger.debug("==== Optimized Vector DB ====")

def clear(self) -> bool:
from sqlalchemy import delete

with self.Session() as sess:
with sess.begin():
stmt = delete(self.table)
sess.execute(stmt)
return True
3 changes: 3 additions & 0 deletions phi/vectordb/qdrant/qdrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,6 @@ def get_count(self) -> int:

def optimize(self) -> None:
pass

def clear(self) -> bool:
return False
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "phidata"
version = "2.3.15"
version = "2.3.16"
description = "Build AI assistants using function calling"
requires-python = ">=3.8"
readme = "README.md"
Expand Down

0 comments on commit 0a8c767

Please sign in to comment.