Spaces:
Runtime error
Runtime error
Commit
·
d5b706b
1
Parent(s):
acbfa77
Change embedding model
Browse files- app.py +21 -15
- compose.yml +1 -1
- populate_db.py +4 -4
app.py
CHANGED
|
@@ -41,8 +41,8 @@ else:
|
|
| 41 |
main()
|
| 42 |
milvus_client.load_collection(collection_name=collection_name)
|
| 43 |
|
| 44 |
-
embedding_model = SentenceTransformer("BAAI/bge-small-en-v1.5")
|
| 45 |
-
|
| 46 |
# Initialize LLM
|
| 47 |
model = ChatNebius(
|
| 48 |
model="Qwen/Qwen3-14B",
|
|
@@ -129,26 +129,24 @@ def setup_rag_chain():
|
|
| 129 |
"context": doc_objects,
|
| 130 |
"history": cl.user_session.get("messages", [])
|
| 131 |
}
|
| 132 |
-
system_prompt = """You are a helpful assistant specialising in disability support, reasonable adjustments, and equality legislation.
|
| 133 |
|
| 134 |
When answering questions, you should:
|
| 135 |
1. Use the provided context documents to inform your response
|
| 136 |
2. Be accurate and helpful
|
| 137 |
-
3.
|
| 138 |
-
4.
|
| 139 |
-
5.
|
| 140 |
-
6.
|
| 141 |
-
7.
|
| 142 |
-
8.
|
| 143 |
-
9.
|
| 144 |
-
10. Do not overemphasize disability in your responses, but rather focus on the support and adjustments that can be made to ensure equality and inclusivity.
|
| 145 |
-
11. If the user asks about a specific disability, provide general information and resources, but do not make assumptions about the individual's experience or needs.
|
| 146 |
-
12. If the user query explicitly asks for a disability-related topic, provide a well-informed response based on the context documents.
|
| 147 |
|
| 148 |
Context documents:
|
| 149 |
{context}
|
| 150 |
|
| 151 |
-
Please provide a clear response using the above context
|
|
|
|
| 152 |
|
| 153 |
# Get the current settings to check if Think mode is enabled
|
| 154 |
settings = cl.user_session.get("settings", {})
|
|
@@ -236,7 +234,7 @@ async def on_chat_start():
|
|
| 236 |
|
| 237 |
@cl.on_settings_update
|
| 238 |
async def setup_agent(settings):
|
| 239 |
-
print("on_settings_update", settings)
|
| 240 |
# Store the settings in the user session so they can be accessed in setup_rag_chain
|
| 241 |
cl.user_session.set("settings", settings)
|
| 242 |
|
|
@@ -259,7 +257,15 @@ async def on_chat_resume(thread: ThreadDict):
|
|
| 259 |
|
| 260 |
cl.user_session.set("messages", messages)
|
| 261 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
|
|
|
|
|
|
|
|
|
|
| 263 |
chain = setup_rag_chain()
|
| 264 |
cl.user_session.set("chain", chain)
|
| 265 |
|
|
|
|
| 41 |
main()
|
| 42 |
milvus_client.load_collection(collection_name=collection_name)
|
| 43 |
|
| 44 |
+
# embedding_model = SentenceTransformer("BAAI/bge-small-en-v1.5")
|
| 45 |
+
embedding_model = SentenceTransformer("Qwen/Qwen3-Embedding-0.6B")
|
| 46 |
# Initialize LLM
|
| 47 |
model = ChatNebius(
|
| 48 |
model="Qwen/Qwen3-14B",
|
|
|
|
| 129 |
"context": doc_objects,
|
| 130 |
"history": cl.user_session.get("messages", [])
|
| 131 |
}
|
| 132 |
+
system_prompt = """You are a helpful assistant specialising in developing non-discriminatory competence standards and disability support, reasonable adjustments, and equality legislation.
|
| 133 |
|
| 134 |
When answering questions, you should:
|
| 135 |
1. Use the provided context documents to inform your response
|
| 136 |
2. Be accurate and helpful
|
| 137 |
+
3. If the context doesn't contain relevant information, say so clearly
|
| 138 |
+
4. Always reply in English
|
| 139 |
+
5. Provide clear recommendations and examples wherever applicable
|
| 140 |
+
6. Do not make assumptions about the user's knowledge or background
|
| 141 |
+
7. If the user asks for a specific law or regulation, provide a brief explanation and cite relevant documents if available.
|
| 142 |
+
8. Do not overemphasize disability in your responses, but rather focus on the support and adjustments that can be made to ensure equality and inclusivity.
|
| 143 |
+
9. If the user query explicitly asks for a disability-related topic, provide a well-informed response based on the context documents.
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
Context documents:
|
| 146 |
{context}
|
| 147 |
|
| 148 |
+
Please provide a clear response using the above context
|
| 149 |
+
"""
|
| 150 |
|
| 151 |
# Get the current settings to check if Think mode is enabled
|
| 152 |
settings = cl.user_session.get("settings", {})
|
|
|
|
| 234 |
|
| 235 |
@cl.on_settings_update
|
| 236 |
async def setup_agent(settings):
|
| 237 |
+
# print("on_settings_update", settings)
|
| 238 |
# Store the settings in the user session so they can be accessed in setup_rag_chain
|
| 239 |
cl.user_session.set("settings", settings)
|
| 240 |
|
|
|
|
| 257 |
|
| 258 |
cl.user_session.set("messages", messages)
|
| 259 |
|
| 260 |
+
settings = await cl.ChatSettings(
|
| 261 |
+
[
|
| 262 |
+
Switch(id="Think", label="Use Deep Thinking", initial=True),
|
| 263 |
+
]
|
| 264 |
+
).send()
|
| 265 |
|
| 266 |
+
# Store initial settings
|
| 267 |
+
cl.user_session.set("settings", {"Think": True}) # Set the default value
|
| 268 |
+
# TODO: # Reinitialize the chain with the current settings
|
| 269 |
chain = setup_rag_chain()
|
| 270 |
cl.user_session.set("chain", chain)
|
| 271 |
|
compose.yml
CHANGED
|
@@ -78,7 +78,7 @@ services:
|
|
| 78 |
- CHAINLIT_AUTH_SECRET=${CHAINLIT_AUTH_SECRET}
|
| 79 |
- OAUTH_GOOGLE_CLIENT_ID=${OAUTH_GOOGLE_CLIENT_ID}
|
| 80 |
- OAUTH_GOOGLE_CLIENT_SECRET=${OAUTH_GOOGLE_CLIENT_SECRET}
|
| 81 |
-
|
| 82 |
depends_on:
|
| 83 |
- standalone
|
| 84 |
|
|
|
|
| 78 |
- CHAINLIT_AUTH_SECRET=${CHAINLIT_AUTH_SECRET}
|
| 79 |
- OAUTH_GOOGLE_CLIENT_ID=${OAUTH_GOOGLE_CLIENT_ID}
|
| 80 |
- OAUTH_GOOGLE_CLIENT_SECRET=${OAUTH_GOOGLE_CLIENT_SECRET}
|
| 81 |
+
|
| 82 |
depends_on:
|
| 83 |
- standalone
|
| 84 |
|
populate_db.py
CHANGED
|
@@ -14,8 +14,8 @@ milvus_client = MilvusClient(uri=MILVUS_URI)
|
|
| 14 |
collection_name = "my_rag_collection"
|
| 15 |
|
| 16 |
# Initialize embedding model
|
| 17 |
-
embedding_model = SentenceTransformer("BAAI/bge-small-en-v1.5")
|
| 18 |
-
|
| 19 |
def emb_text(text):
|
| 20 |
"""Generate embeddings for text using the sentence transformer model."""
|
| 21 |
return embedding_model.encode([text], normalize_embeddings=True).tolist()[0]
|
|
@@ -29,8 +29,8 @@ def create_collection():
|
|
| 29 |
# Create Milvus collection schema
|
| 30 |
schema = milvus_client.create_schema(auto_id=False, enable_dynamic_field=False)
|
| 31 |
schema.add_field(field_name="id", datatype=DataType.INT64, is_primary=True)
|
| 32 |
-
schema.add_field(field_name="vector", datatype=DataType.FLOAT_VECTOR, dim=
|
| 33 |
-
schema.add_field(field_name="text", datatype=DataType.VARCHAR
|
| 34 |
schema.add_field(field_name="metadata", datatype=DataType.JSON)
|
| 35 |
|
| 36 |
# Create index for vector search
|
|
|
|
| 14 |
collection_name = "my_rag_collection"
|
| 15 |
|
| 16 |
# Initialize embedding model
|
| 17 |
+
# embedding_model = SentenceTransformer("BAAI/bge-small-en-v1.5")
|
| 18 |
+
embedding_model = SentenceTransformer("Qwen/Qwen3-Embedding-0.6B")
|
| 19 |
def emb_text(text):
|
| 20 |
"""Generate embeddings for text using the sentence transformer model."""
|
| 21 |
return embedding_model.encode([text], normalize_embeddings=True).tolist()[0]
|
|
|
|
| 29 |
# Create Milvus collection schema
|
| 30 |
schema = milvus_client.create_schema(auto_id=False, enable_dynamic_field=False)
|
| 31 |
schema.add_field(field_name="id", datatype=DataType.INT64, is_primary=True)
|
| 32 |
+
schema.add_field(field_name="vector", datatype=DataType.FLOAT_VECTOR, dim=1024) # Qwen/Qwen3-Embedding-0.6B dimension
|
| 33 |
+
schema.add_field(field_name="text", datatype=DataType.VARCHAR) # 32KB max
|
| 34 |
schema.add_field(field_name="metadata", datatype=DataType.JSON)
|
| 35 |
|
| 36 |
# Create index for vector search
|