-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add-azureembedder-cookbook-example-phi-1918
- Loading branch information
Showing
12 changed files
with
140 additions
and
133 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,19 @@ | ||
from phi.agent import AgentKnowledge | ||
from phi.vectordb.pgvector import PgVector | ||
from phi.embedder.azure_openai import AzureOpenAIEmbedder | ||
|
||
embeddings = AzureOpenAIEmbedder().get_embedding("The quick brown fox jumps over the lazy dog.") | ||
|
||
# Print the embeddings and their dimensions | ||
print(f"Embeddings: {embeddings[:5]}") | ||
print(f"Dimensions: {len(embeddings)}") | ||
|
||
# Example usage: | ||
knowledge_base = AgentKnowledge( | ||
vector_db=PgVector( | ||
db_url="postgresql+psycopg://ai:ai@localhost:5532/ai", | ||
table_name="azure_openai_embeddings", | ||
embedder=AzureOpenAIEmbedder(), | ||
), | ||
num_documents=2, | ||
) |
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 |
---|---|---|
@@ -1,27 +1,19 @@ | ||
import os | ||
|
||
from phi.agent import Agent, AgentKnowledge | ||
from phi.agent import AgentKnowledge | ||
from phi.vectordb.pgvector import PgVector | ||
from phi.embedder.fireworks import FireworksEmbedder | ||
|
||
# Create knowledge base | ||
embeddings = FireworksEmbedder().get_embedding("The quick brown fox jumps over the lazy dog.") | ||
|
||
# Print the embeddings and their dimensions | ||
print(f"Embeddings: {embeddings[:5]}") | ||
print(f"Dimensions: {len(embeddings)}") | ||
|
||
# Example usage: | ||
knowledge_base = AgentKnowledge( | ||
vector_db=PgVector( | ||
db_url="postgresql+psycopg://ai:ai@localhost:5532/ai", | ||
table_name="fireworks_embeddings", | ||
embedder=FireworksEmbedder( | ||
api_key=os.getenv("FIREWORKS_API_KEY"), | ||
dimensions=768, | ||
), | ||
embedder=FireworksEmbedder(), | ||
), | ||
num_documents=2, | ||
) | ||
|
||
# Add information to the knowledge base | ||
knowledge_base.load_text( | ||
"This classic spaghetti carbonara combines perfectly cooked al dente pasta " | ||
"with crispy pancetta and creamy eggs that create a luscious sauce." | ||
) | ||
|
||
# Add the knowledge base to the Agent | ||
agent = Agent(knowledge_base=knowledge_base) |
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 |
---|---|---|
@@ -1,27 +1,19 @@ | ||
import os | ||
|
||
from phi.agent import Agent, AgentKnowledge | ||
from phi.agent import AgentKnowledge | ||
from phi.vectordb.pgvector import PgVector | ||
from phi.embedder.google import GeminiEmbedder | ||
|
||
# Create knowledge base | ||
embeddings = GeminiEmbedder().get_embedding("The quick brown fox jumps over the lazy dog.") | ||
|
||
# Print the embeddings and their dimensions | ||
print(f"Embeddings: {embeddings[:5]}") | ||
print(f"Dimensions: {len(embeddings)}") | ||
|
||
# Example usage: | ||
knowledge_base = AgentKnowledge( | ||
vector_db=PgVector( | ||
db_url="postgresql+psycopg://ai:ai@localhost:5532/ai", | ||
table_name="gemini_embeddings", | ||
embedder=GeminiEmbedder( | ||
api_key=os.getenv("GOOGLE_API_KEY"), | ||
dimensions=768, | ||
), | ||
embedder=GeminiEmbedder(), | ||
), | ||
num_documents=2, | ||
) | ||
|
||
# Add information to the knowledge base | ||
knowledge_base.load_text( | ||
"This classic spaghetti carbonara combines perfectly cooked al dente pasta " | ||
"with crispy pancetta and creamy eggs that create a luscious sauce." | ||
) | ||
|
||
# Add the knowledge base to the Agent | ||
agent = Agent(knowledge_base=knowledge_base) |
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,19 @@ | ||
from phi.agent import AgentKnowledge | ||
from phi.vectordb.pgvector import PgVector | ||
from phi.embedder.huggingface import HuggingfaceCustomEmbedder | ||
|
||
embeddings = HuggingfaceCustomEmbedder().get_embedding("The quick brown fox jumps over the lazy dog.") | ||
|
||
# Print the embeddings and their dimensions | ||
print(f"Embeddings: {embeddings[:5]}") | ||
print(f"Dimensions: {len(embeddings)}") | ||
|
||
# Example usage: | ||
knowledge_base = AgentKnowledge( | ||
vector_db=PgVector( | ||
db_url="postgresql+psycopg://ai:ai@localhost:5532/ai", | ||
table_name="huggingface_embeddings", | ||
embedder=HuggingfaceCustomEmbedder(), | ||
), | ||
num_documents=2, | ||
) |
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 |
---|---|---|
@@ -1,26 +1,19 @@ | ||
import os | ||
from phi.agent import Agent, AgentKnowledge | ||
from phi.agent import AgentKnowledge | ||
from phi.vectordb.pgvector import PgVector | ||
from phi.embedder.mistral import MistralEmbedder | ||
|
||
# Create knowledge base | ||
embeddings = MistralEmbedder().get_embedding("The quick brown fox jumps over the lazy dog.") | ||
|
||
# Print the embeddings and their dimensions | ||
print(f"Embeddings: {embeddings[:5]}") | ||
print(f"Dimensions: {len(embeddings)}") | ||
|
||
# Example usage: | ||
knowledge_base = AgentKnowledge( | ||
vector_db=PgVector( | ||
db_url="postgresql+psycopg://ai:ai@localhost:5532/ai", | ||
table_name="mistral_embeddings", | ||
embedder=MistralEmbedder( | ||
api_key=os.getenv("MISTRAL_API_KEY"), | ||
dimensions=1024, | ||
), | ||
embedder=MistralEmbedder(), | ||
), | ||
num_documents=2, | ||
) | ||
|
||
# Add information to the knowledge base | ||
knowledge_base.load_text( | ||
"This classic spaghetti carbonara combines perfectly cooked al dente pasta " | ||
"with crispy pancetta and creamy eggs that create a luscious sauce." | ||
) | ||
|
||
# Add the knowledge base to the Agent | ||
agent = Agent(knowledge_base=knowledge_base) |
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 |
---|---|---|
@@ -1,25 +1,19 @@ | ||
from phi.agent import Agent, AgentKnowledge | ||
from phi.agent import AgentKnowledge | ||
from phi.vectordb.pgvector import PgVector | ||
from phi.embedder.ollama import OllamaEmbedder | ||
|
||
# Create knowledge base | ||
embeddings = OllamaEmbedder().get_embedding("The quick brown fox jumps over the lazy dog.") | ||
|
||
# Print the embeddings and their dimensions | ||
print(f"Embeddings: {embeddings[:5]}") | ||
print(f"Dimensions: {len(embeddings)}") | ||
|
||
# Example usage: | ||
knowledge_base = AgentKnowledge( | ||
vector_db=PgVector( | ||
db_url="postgresql+psycopg://ai:ai@localhost:5532/ai", | ||
table_name="ollama_embeddings", | ||
embedder=OllamaEmbedder( | ||
model="openhermes", | ||
dimensions=4096, | ||
), | ||
embedder=OllamaEmbedder(), | ||
), | ||
num_documents=2, | ||
) | ||
|
||
# Add information to the knowledge base | ||
knowledge_base.load_text( | ||
"This classic spaghetti carbonara combines perfectly cooked al dente pasta " | ||
"with crispy pancetta and creamy eggs that create a luscious sauce." | ||
) | ||
|
||
# Add the knowledge base to the Agent | ||
agent = Agent(knowledge_base=knowledge_base) |
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 |
---|---|---|
@@ -1,27 +1,19 @@ | ||
import os | ||
|
||
from phi.agent import Agent, AgentKnowledge | ||
from phi.agent import AgentKnowledge | ||
from phi.vectordb.pgvector import PgVector | ||
from phi.embedder.openai import OpenAIEmbedder | ||
|
||
# Create knowledge base | ||
embeddings = OpenAIEmbedder().get_embedding("Embed me") | ||
|
||
# Print the embeddings and their dimensions | ||
print(f"Embeddings: {embeddings[:5]}") | ||
print(f"Dimensions: {len(embeddings)}") | ||
|
||
# Example usage: | ||
knowledge_base = AgentKnowledge( | ||
vector_db=PgVector( | ||
db_url="postgresql+psycopg://ai:ai@localhost:5532/ai", | ||
table_name="openai_embeddings", | ||
embedder=OpenAIEmbedder( | ||
api_key=os.getenv("OPENAI_API_KEY"), | ||
dimensions=1536, | ||
), | ||
embedder=OpenAIEmbedder(), | ||
), | ||
num_documents=2, | ||
) | ||
|
||
# Add information to the knowledge base | ||
knowledge_base.load_text( | ||
"This classic spaghetti carbonara combines perfectly cooked al dente pasta " | ||
"with crispy pancetta and creamy eggs that create a luscious sauce." | ||
) | ||
|
||
# Add the knowledge base to the Agent | ||
agent = Agent(knowledge_base=knowledge_base) |
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 |
---|---|---|
@@ -1,20 +1,19 @@ | ||
from phi.agent import AgentKnowledge | ||
from phi.vectordb.pgvector import PgVector | ||
from phi.embedder.fastembed import FastEmbedEmbedder | ||
from typing import List | ||
|
||
documents: List[str] = [ | ||
"This classic spaghetti carbonara combines perfectly cooked al dente pasta", | ||
"with crispy pancetta, which adds a savory crunch and depth of flavor,", | ||
"creamy eggs that create a luscious sauce when mixed with the hot pasta,", | ||
"and a generous sprinkle of freshly grated Parmesan cheese", | ||
"for a comforting, flavorful dish that's sure to impress any pasta lover.", | ||
"Finish with a dash of black pepper and a garnish of parsley for a touch of freshness.", | ||
] | ||
embeddings = FastEmbedEmbedder().get_embedding("The quick brown fox jumps over the lazy dog.") | ||
|
||
"""FastEmbed supported models can be found here: https://qdrant.github.io/fastembed/examples/Supported_Models/""" | ||
# Print the embeddings and their dimensions | ||
print(f"Embeddings: {embeddings[:5]}") | ||
print(f"Dimensions: {len(embeddings)}") | ||
|
||
embedder = FastEmbedEmbedder( | ||
# model="BAAI/bge-small-en-v1.5" | ||
# Example usage: | ||
knowledge_base = AgentKnowledge( | ||
vector_db=PgVector( | ||
db_url="postgresql+psycopg://ai:ai@localhost:5532/ai", | ||
table_name="qdrant_embeddings", | ||
embedder=FastEmbedEmbedder(), | ||
), | ||
num_documents=2, | ||
) | ||
|
||
embeddings = embedder.get_embedding("\n".join(documents)) | ||
print(embeddings[0]) |
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,19 @@ | ||
from phi.agent import AgentKnowledge | ||
from phi.vectordb.pgvector import PgVector | ||
from phi.embedder.sentence_transformer import SentenceTransformerEmbedder | ||
|
||
embeddings = SentenceTransformerEmbedder().get_embedding("The quick brown fox jumps over the lazy dog.") | ||
|
||
# Print the embeddings and their dimensions | ||
print(f"Embeddings: {embeddings[:5]}") | ||
print(f"Dimensions: {len(embeddings)}") | ||
|
||
# Example usage: | ||
knowledge_base = AgentKnowledge( | ||
vector_db=PgVector( | ||
db_url="postgresql+psycopg://ai:ai@localhost:5532/ai", | ||
table_name="sentence_transformer_embeddings", | ||
embedder=SentenceTransformerEmbedder(), | ||
), | ||
num_documents=2, | ||
) |
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 |
---|---|---|
@@ -1,27 +1,19 @@ | ||
import os | ||
|
||
from phi.agent import Agent, AgentKnowledge | ||
from phi.agent import AgentKnowledge | ||
from phi.vectordb.pgvector import PgVector | ||
from phi.embedder.together import TogetherEmbedder | ||
|
||
# Create knowledge base | ||
embeddings = TogetherEmbedder().get_embedding("The quick brown fox jumps over the lazy dog.") | ||
|
||
# Print the embeddings and their dimensions | ||
print(f"Embeddings: {embeddings[:5]}") | ||
print(f"Dimensions: {len(embeddings)}") | ||
|
||
# Example usage: | ||
knowledge_base = AgentKnowledge( | ||
vector_db=PgVector( | ||
db_url="postgresql+psycopg://ai:ai@localhost:5532/ai", | ||
table_name="together_embeddings", | ||
embedder=TogetherEmbedder( | ||
api_key=os.getenv("TOGETHER_API_KEY"), | ||
dimensions=768, | ||
), | ||
embedder=TogetherEmbedder(), | ||
), | ||
num_documents=2, | ||
) | ||
|
||
# Add information to the knowledge base | ||
knowledge_base.load_text( | ||
"This classic spaghetti carbonara combines perfectly cooked al dente pasta " | ||
"with crispy pancetta and creamy eggs that create a luscious sauce." | ||
) | ||
|
||
# Add the knowledge base to the Agent | ||
agent = Agent(knowledge_base=knowledge_base) |
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 |
---|---|---|
@@ -1,27 +1,19 @@ | ||
import os | ||
|
||
from phi.agent import Agent, AgentKnowledge | ||
from phi.agent import AgentKnowledge | ||
from phi.vectordb.pgvector import PgVector | ||
from phi.embedder.voyageai import VoyageAIEmbedder | ||
|
||
# Create knowledge base | ||
embeddings = VoyageAIEmbedder().get_embedding("The quick brown fox jumps over the lazy dog.") | ||
|
||
# Print the embeddings and their dimensions | ||
print(f"Embeddings: {embeddings[:5]}") | ||
print(f"Dimensions: {len(embeddings)}") | ||
|
||
# Example usage: | ||
knowledge_base = AgentKnowledge( | ||
vector_db=PgVector( | ||
db_url="postgresql+psycopg://ai:ai@localhost:5532/ai", | ||
table_name="voyageai_embeddings", | ||
embedder=VoyageAIEmbedder( | ||
api_key=os.getenv("VOYAGE_API_KEY"), | ||
dimensions=1024, | ||
), | ||
embedder=VoyageAIEmbedder(), | ||
), | ||
num_documents=2, | ||
) | ||
|
||
# Add information to the knowledge base | ||
knowledge_base.load_text( | ||
"This classic spaghetti carbonara combines perfectly cooked al dente pasta " | ||
"with crispy pancetta and creamy eggs that create a luscious sauce." | ||
) | ||
|
||
# Add the knowledge base to the Agent | ||
agent = Agent(knowledge_base=knowledge_base) |
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