Skip to content

Commit

Permalink
Merge branch 'develop' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
shakkernerd authored Jan 8, 2025
2 parents 5eb2ecc + b319ff1 commit 3de40d0
Show file tree
Hide file tree
Showing 49 changed files with 3,827 additions and 972 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/jsdoc-automation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ on:
root_directory:
description: "Only scans files in this directory (relative to repository root, e.g., packages/core/src)"
required: true
default: "packages/plugin-near/"
default: "packages/plugin-bootstrap"
type: string
excluded_directories:
description: "Directories to exclude from scanning (comma-separated, relative to root_directory)"
Expand All @@ -37,11 +37,6 @@ on:
required: false
default: "develop"
type: string
language:
description: "Documentation language (e.g., English, Spanish, French)"
required: true
default: "English"
type: string

jobs:
generate-docs:
Expand Down Expand Up @@ -99,6 +94,5 @@ jobs:
INPUT_EXCLUDED_DIRECTORIES: ${{ inputs.excluded_directories }}
INPUT_REVIEWERS: ${{ inputs.reviewers }}
INPUT_BRANCH: ${{ inputs.branch }}
INPUT_LANGUAGE: ${{ inputs.language }}
INPUT_JSDOC: ${{ inputs.jsdoc }}
INPUT_README: ${{ inputs.readme }}
1 change: 1 addition & 0 deletions agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@elizaos/plugin-goat": "workspace:*",
"@elizaos/plugin-icp": "workspace:*",
"@elizaos/plugin-image-generation": "workspace:*",
"@elizaos/plugin-movement": "workspace:*",
"@elizaos/plugin-nft-generation": "workspace:*",
"@elizaos/plugin-node": "workspace:*",
"@elizaos/plugin-solana": "workspace:*",
Expand Down
10 changes: 4 additions & 6 deletions docs/community/Notes/lore.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,10 @@ Week 1 Recap: ai16z Launch and Early Developments

4. Infrastructure / Contributor Pipeline

![image](/img/website_v1.jpg)

- New website launched: https://ai16z.ai
- Dework for crypto bounties, invite link, still WIP: https://app.dework.xyz/i/7KbiY0TFRoJhMx0251BvUP
- Twitter account transferred to partners: https://x.com/ai16zdao
- Media/design assets consolidated on GitHub: https://github.com/ai16z/assets
- New website launched: [https://elizaos.ai](https://elizaos.ai/)
- Dework for crypto bounties, invite link, still WIP: https://app.dework.xyz/i/7KbiY0TFRoJhMx0251BvUP
- Twitter account transferred to partners: https://x.com/ai16zdao
- Media/design assets consolidated on GitHub: https://github.com/ai16z/assets

5. Community Engagement and Spaces

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,63 @@ CREATE TABLE IF NOT EXISTS "public"."rooms" (
"createdAt" timestamp with time zone DEFAULT ("now"() AT TIME ZONE 'utc'::"text") NOT NULL
);

CREATE OR REPLACE FUNCTION "public"."search_knowledge"(
"query_embedding" "extensions"."vector",
"query_agent_id" "uuid",
"match_threshold" double precision,
"match_count" integer,
"search_text" text
) RETURNS TABLE (
"id" "uuid",
"agentId" "uuid",
"content" "jsonb",
"embedding" "extensions"."vector",
"createdAt" timestamp with time zone,
"similarity" double precision
) LANGUAGE "plpgsql" AS $$
BEGIN
RETURN QUERY
WITH vector_matches AS (
SELECT id,
1 - (embedding <=> query_embedding) as vector_score
FROM knowledge
WHERE (agentId IS NULL AND isShared = true) OR agentId = query_agent_id
AND embedding IS NOT NULL
),
keyword_matches AS (
SELECT id,
CASE
WHEN content->>'text' ILIKE '%' || search_text || '%' THEN 3.0
ELSE 1.0
END *
CASE
WHEN content->'metadata'->>'isChunk' = 'true' THEN 1.5
WHEN content->'metadata'->>'isMain' = 'true' THEN 1.2
ELSE 1.0
END as keyword_score
FROM knowledge
WHERE (agentId IS NULL AND isShared = true) OR agentId = query_agent_id
)
SELECT
k.id,
k."agentId",
k.content,
k.embedding,
k."createdAt",
(v.vector_score * kw.keyword_score) as similarity
FROM knowledge k
JOIN vector_matches v ON k.id = v.id
LEFT JOIN keyword_matches kw ON k.id = kw.id
WHERE (k.agentId IS NULL AND k.isShared = true) OR k.agentId = query_agent_id
AND (
v.vector_score >= match_threshold
OR (kw.keyword_score > 1.0 AND v.vector_score >= 0.3)
)
ORDER BY similarity DESC
LIMIT match_count;
END;
$$;

ALTER TABLE "public"."rooms" OWNER TO "postgres";

ALTER TABLE ONLY "public"."relationships"
Expand Down Expand Up @@ -564,6 +621,9 @@ ALTER TABLE ONLY "public"."relationships"
ALTER TABLE ONLY "public"."relationships"
ADD CONSTRAINT "relationships_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."accounts"("id");

ALTER TABLE ONLY "public"."knowledge"
ADD CONSTRAINT "knowledge_agentId_fkey" FOREIGN KEY ("agentId") REFERENCES "public"."accounts"("id") ON DELETE CASCADE;

CREATE POLICY "Can select and update all data" ON "public"."accounts" USING (("auth"."uid"() = "id")) WITH CHECK (("auth"."uid"() = "id"));

CREATE POLICY "Enable delete for users based on userId" ON "public"."goals" FOR DELETE TO "authenticated" USING (("auth"."uid"() = "userId"));
Expand Down Expand Up @@ -600,6 +660,18 @@ CREATE POLICY "Enable update for users of own id" ON "public"."rooms" FOR UPDATE

CREATE POLICY "Enable users to delete their own relationships/friendships" ON "public"."relationships" FOR DELETE TO "authenticated" USING ((("auth"."uid"() = "userA") OR ("auth"."uid"() = "userB")));

CREATE POLICY "Enable read access for all users" ON "public"."knowledge"
FOR SELECT USING (true);

CREATE POLICY "Enable insert for authenticated users only" ON "public"."knowledge"
FOR INSERT TO "authenticated" WITH CHECK (true);

CREATE POLICY "Enable update for authenticated users" ON "public"."knowledge"
FOR UPDATE TO "authenticated" USING (true) WITH CHECK (true);

CREATE POLICY "Enable delete for users based on agentId" ON "public"."knowledge"
FOR DELETE TO "authenticated" USING (("auth"."uid"() = "agentId"));

ALTER TABLE "public"."accounts" ENABLE ROW LEVEL SECURITY;

ALTER TABLE "public"."goals" ENABLE ROW LEVEL SECURITY;
Expand All @@ -614,6 +686,8 @@ ALTER TABLE "public"."relationships" ENABLE ROW LEVEL SECURITY;

ALTER TABLE "public"."rooms" ENABLE ROW LEVEL SECURITY;

ALTER TABLE "public"."knowledge" ENABLE ROW LEVEL SECURITY;

CREATE POLICY "select_own_account" ON "public"."accounts" FOR SELECT USING (("auth"."uid"() = "id"));

GRANT USAGE ON SCHEMA "public" TO "postgres";
Expand Down Expand Up @@ -703,14 +777,18 @@ GRANT ALL ON TABLE "public"."secrets" TO "service_role";
GRANT ALL ON TABLE "public"."secrets" TO "supabase_admin";
GRANT ALL ON TABLE "public"."secrets" TO "supabase_auth_admin";

GRANT ALL ON TABLE "public"."knowledge" TO "authenticated";
GRANT ALL ON TABLE "public"."knowledge" TO "service_role";
GRANT ALL ON TABLE "public"."knowledge" TO "supabase_admin";
GRANT ALL ON TABLE "public"."knowledge" TO "supabase_auth_admin";

GRANT ALL ON FUNCTION "public"."get_participant_userState"("roomId" "uuid", "userId" "uuid") TO "authenticated";
GRANT ALL ON FUNCTION "public"."get_participant_userState"("roomId" "uuid", "userId" "uuid") TO "service_role";
GRANT ALL ON FUNCTION "public"."get_participant_userState"("roomId" "uuid", "userId" "uuid") TO "supabase_admin";
GRANT ALL ON FUNCTION "public"."get_participant_userState"("roomId" "uuid", "userId" "uuid") TO "supabase_auth_admin";

GRANT ALL ON FUNCTION "public"."set_participant_userState"("roomId" "uuid", "userId" "uuid", "state" "text") TO "authenticated";
GRANT ALL ON FUNCTION "public"."set_participant_userState"("roomId" "uuid", "userId" "uuid", "state" "text") TO "service_role";
GRANT ALL ON FUNCTION "public"."set_participant_userState"("roomId" "uuid", "userId" "uuid", "state" "text") TO "service_role";
GRANT ALL ON FUNCTION "public"."set_participant_userState"("roomId" "uuid", "userId" "uuid", "state" "text") TO "supabase_admin";
GRANT ALL ON FUNCTION "public"."set_participant_userState"("roomId" "uuid", "userId" "uuid", "state" "text") TO "supabase_auth_admin";

Expand All @@ -733,4 +811,9 @@ ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON TAB
ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON TABLES TO "supabase_admin";
ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON TABLES TO "supabase_auth_admin";

GRANT ALL ON FUNCTION "public"."search_knowledge"("query_embedding" "extensions"."vector", "query_agent_id" "uuid", "match_threshold" double precision, "match_count" integer, "search_text" text) TO "authenticated";
GRANT ALL ON FUNCTION "public"."search_knowledge"("query_embedding" "extensions"."vector", "query_agent_id" "uuid", "match_threshold" double precision, "match_count" integer, "search_text" text) TO "service_role";
GRANT ALL ON FUNCTION "public"."search_knowledge"("query_embedding" "extensions"."vector", "query_agent_id" "uuid", "match_threshold" double precision, "match_count" integer, "search_text" text) TO "supabase_admin";
GRANT ALL ON FUNCTION "public"."search_knowledge"("query_embedding" "extensions"."vector", "query_agent_id" "uuid", "match_threshold" double precision, "match_count" integer, "search_text" text) TO "supabase_auth_admin";

RESET ALL;
28 changes: 28 additions & 0 deletions packages/adapter-postgres/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
-- DROP TABLE IF EXISTS memories CASCADE;
-- DROP TABLE IF EXISTS rooms CASCADE;
-- DROP TABLE IF EXISTS accounts CASCADE;
-- DROP TABLE IF EXISTS knowledge CASCADE;


CREATE EXTENSION IF NOT EXISTS vector;
Expand Down Expand Up @@ -130,11 +131,38 @@ CREATE TABLE IF NOT EXISTS cache (
PRIMARY KEY ("key", "agentId")
);

DO $$
DECLARE
vector_dim INTEGER;
BEGIN
vector_dim := get_embedding_dimension();

EXECUTE format('
CREATE TABLE IF NOT EXISTS knowledge (
"id" UUID PRIMARY KEY,
"agentId" UUID REFERENCES accounts("id"),
"content" JSONB NOT NULL,
"embedding" vector(%s),
"createdAt" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
"isMain" BOOLEAN DEFAULT FALSE,
"originalId" UUID REFERENCES knowledge("id"),
"chunkIndex" INTEGER,
"isShared" BOOLEAN DEFAULT FALSE,
CHECK((isShared = true AND "agentId" IS NULL) OR (isShared = false AND "agentId" IS NOT NULL))
)', vector_dim);
END $$;

-- Indexes
CREATE INDEX IF NOT EXISTS idx_memories_embedding ON memories USING hnsw ("embedding" vector_cosine_ops);
CREATE INDEX IF NOT EXISTS idx_memories_type_room ON memories("type", "roomId");
CREATE INDEX IF NOT EXISTS idx_participants_user ON participants("userId");
CREATE INDEX IF NOT EXISTS idx_participants_room ON participants("roomId");
CREATE INDEX IF NOT EXISTS idx_relationships_users ON relationships("userA", "userB");
CREATE INDEX IF NOT EXISTS idx_knowledge_agent ON knowledge("agentId");
CREATE INDEX IF NOT EXISTS idx_knowledge_agent_main ON knowledge("agentId", "isMain");
CREATE INDEX IF NOT EXISTS idx_knowledge_original ON knowledge("originalId");
CREATE INDEX IF NOT EXISTS idx_knowledge_created ON knowledge("agentId", "createdAt");
CREATE INDEX IF NOT EXISTS idx_knowledge_shared ON knowledge("isShared");
CREATE INDEX IF NOT EXISTS idx_knowledge_embedding ON knowledge USING ivfflat (embedding vector_cosine_ops);

COMMIT;
Loading

0 comments on commit 3de40d0

Please sign in to comment.